Our blazing fast Grid component built with pure JavaScript


Post by vadim_g »

Hi guys,

Sometimes we need to check if store is loaded or not (to track if there was at least 1 first request to server made, or one store.data assigned). We've come up with a solution that covers most of the cases (we need to add tests for store.tree: true and with lazy too)

Would you see adding this as a feature request ? Also do you see any issues with this solution ?

import Store from '@bryntum/grid/source/lib/Core/data/Store';

const { afterLoadData } = Store.prototype;

Store.prototype.afterLoadData = function () {
	// _loadedOnce is used in StoreLazyLoadPlugin, so let's reuse it for isLoaded too
	this._loadedOnce = true;

	if (afterLoadData) {
		afterLoadData.apply(this, arguments);
	}
};

/**
 * _loadedOnce is used in StoreLazyLoadPlugin, so let's reuse it for isLoaded too
 * @return {boolean}
 */
Store.prototype.isLoaded = function () {
	return Boolean(this._loadedOnce);
};

Thanks
Vadim


Post by alex.l »

Hi Vadim,

What is the use case of this feature? We might add a FR if it might be useful for many users, maybe when you describe a use case it will sounds useful. In case you're good to achieve this by few lines of the code and not a common thing our users might be need - it doesn't worth a FR.

Your solution looks ok to me.

All the best,
Alex Lazarev

How to ask for help? Please read our Support Policy

We do not write the code in bounds of forum support. If you need help with development, contact us via bryntum.com/services


Post by vadim_g »

Hey Alex,

well, most of the cases is about building custom components or forms, and you must init some data only after the store is loaded. So we check if store is loaded, we call the respective method otherwise "store.on('load', this.callSomeInitMethod)".The store usually is passed as a config, so it can be local or remote...isLoaded is in handy to check, plus as I requested eariler for an abstract consistent load event (as now is load and loadPage separately) which in conbination leads to making sure the dependencies are synced or initialized ok between the components and configs in a Form/Dialog.

We are fine with the code we've come up with, the only worry, as always is that if is not an OOTB feature, then we need to make sure during the upgrades these are not broken, and if we get too many of these, the upgrades become time consuming, where as if they are OOTB, you take them in account when you change things, so it is easier for everybody.

More than this, I saw you added _loadedOnce private field already. :)

Vadim.


Post by alex.l »

Hi,

Discussed with dev team, here is a FR for that https://github.com/bryntum/support/issues/12161
Thank you for your questions and suggestions, very appreciated!

All the best,
Alex Lazarev

How to ask for help? Please read our Support Policy

We do not write the code in bounds of forum support. If you need help with development, contact us via bryntum.com/services


Post by vadim_g »

Thanks for considering it.


Post Reply