Ability to pass callback function during store creation for store initialisation and updates
KennyYe opened this issue · comments
We would like the ability to pass in certain callback functions when stores are created that would track:
- Store initialisation
- Store changes
const onStoreInit = (storeInstance) => {
// do something when store initialises
};
const onStoreUpdate = (storeInstance, actionDispatched) => {
// do something when store updates
};
export const store = createStore({
...
name: 'my-store',
onStoreInit,
onStoreUpdate,
});
This would allow us to implement custom logic into our stores changing without having to mount many useEffects
to track and respond to these changes.
Container
has similar abilities, except onUpdate
is triggered when container props are changed, not when it's state is updated.
You shall not be able to send a good message from a static function defined as a part of the store due to the absence of "context" and thus the necessity to communicate with other elements using globals. Can we do our best to use fewer globals?
Right hooking into createContainer
would be a much better solution. perhaps there would be another option for onStoreUpdate
as you mentioned that onUpdate
only listens for changes to the container props.