Create registerPreStateInit hook
ivalexandr opened this issue · 2 comments
ivalexandr commented
Discussed in #381
Originally posted by ivalexandr November 19, 2022
Hello. Why does the documentaion say that state in Elf is immutable? After all, we can change it without calling update
method.
Can we change this behavior and somehow protect from mutations the object obtained from the store?
NetanelBasal commented
Add a new registerPreStoreInit
hook that takes the provided initial state and returns it.
import { elfHooks, deepFreeze } from '@ngneat/elf';
if (!environment.production) {
elfHooks.registerPreStateInit((initialState, storeName) => {
return deepFreeze(initialState);
});
}
NetanelBasal commented
@ivalexandr, you're welcome to create a PR. It should be straightforward.