You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
All states are read from storage on InitState and on UpdateState. This brings the app to the problem of inconsistent data when state was changed (in memory) but then overwritten from storage. To fix this I propose: on UpdateState get only addedStates from storage.
Also, it would be nice to:
make sure that state was read once from storage
allow writing state to storage only after data was read from storage.
I have added a test on this.
import{TestBed}from'@angular/core/testing';import{NgxsAsyncStoragePluginModule}from'@ngxs-labs/async-storage-plugin';import{NgxsModule,State,Store,UpdateState}from'@ngxs/store';describe('read state from storage once',()=>{beforeEach(()=>{TestBed.configureTestingModule({imports: [NgxsModule.forRoot([StateToStore]),NgxsAsyncStoragePluginModule.forRoot(KeyValueStorageMock,{key: [StateToStore.name]})],providers: [KeyValueStorageMock]});});it(`does not get again ${StateToStore.name} when ${UpdateState.name} dispatched`,async()=>{conststore=TestBed.get(Store)asStore;// was get on InitStateexpect(getItemSpy).toHaveBeenCalledWith(StateToStore.name);getItemSpy.calls.reset();awaitstore.dispatch(newUpdateState()).toPromise();expect(getItemSpy).not.toHaveBeenCalledWith(StateToStore.name);});});constgetItemSpy=jasmine.createSpy('getItem');classKeyValueStorageMock{getItem(key: string){console.log(key);returngetItemSpy(key);}setItem(){}}
@State<string>({defaults: 'default',name: StateToStore.name})
class StateToStore {constructor(){}}
The text was updated successfully, but these errors were encountered:
All states are read from storage on
InitState
and onUpdateState
. This brings the app to the problem of inconsistent data when state was changed (in memory) but then overwritten from storage. To fix this I propose: on UpdateState get onlyaddedStates
from storage.Also, it would be nice to:
I have added a test on this.
The text was updated successfully, but these errors were encountered: