[ ] Regression (a behavior that used to work and stopped working in a new release)
[X] Bug report
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:
The global resettable option can cause problems with EntityStore related to its initialState.
Here's the steps how I came to this problem:
persistState plugin in my application! So I installed that :-)cartItemsStore.reset()resettable option. That's great! akitaConfig({
resettable: true
});
resettable after a particular store has been created then that particular store does not have an initial state to be reset with.EntityStore this default initial state is critical because it contains { ids:[], entities: {} }.reset therefore completely wiped out my EntityStore to {}, hence the error when trying to access ids property.akitaConfig config should be placed in my application in order to prevent this. With complex dependency injection it can't just go in app.component.ts constructor because stores may already be created.set({ids: [], entities: {}}) if there is no _initialState available?Just set resettable on the individual store configuration - so it will have an initial state.
App crashed in an unexpected way due to null reference error.
All
You can't call akitaConfig() after you created the stores. You should call it in the main.ts.
The second option is to add the resettable property in the store you need it:
@StoreConfig({ name: 'cart', resettable: true })
export class CartStore extends EntityStore<CartState, CartItem> {
constructor() {
super();
}
}
Most helpful comment
You can't call
akitaConfig()after you created the stores. You should call it in themain.ts.The second option is to add the
resettableproperty in the store you need it: