Hooks
Elf allows customizing some of the behavior via elfHooks
registerPreStoreUpdate
Provide a function to modify the store value after reducers has run.
The callback function takes three arguments:
currentState
- state before reducers has runnextState
- state after reducers has runstoreName
- the name of the store
One scenario when this functionality could be useful is when a developer wants to prevent bugs associated with mutability by freezing the store value during the development:
import { elfHooks, deepFreeze } from '@ngneat/elf';
if (!environment.production) {
elfHooks.registerPreStoreUpdate((currentState, nextState, storeName) => {
return deepFreeze(nextState);
});
}
registerPreStateInit
Provide a function to modify initial state of the store.
The callback function takes two arguments:
initialState
- the initial state of the storestoreName
- the name of the store
It could be useful is when a developer wants to prevents bugs associated with mutability by freezing initial state value during the development:
import { elfHooks, deepFreeze } from '@ngneat/elf';
if (!environment.production) {
elfHooks.registerPreStateInit((initialState, storeName) => {
return deepFreeze(initialState);
});
}