btroncone / ngrx-store-localstorage

Simple syncing between @ngrx store and local storage

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rehydrate adds a root state element to my store

fskaeh opened this issue · comments

I have an app where the state is shaped like this;

{ locations: { searchLocations: [...] editLocation: {...} } }

For this state, I have an ActionReducerMap passed in StoreModule.forRoot in AppModule:
export const reducers: ActionReducerMap<IAppState> = { locations: fromLocations.reducer };
export function reducer(state: ILocationsState | undefined, action: Action) { return locationsReducer(state, action); }

I set up ngrx-store-localstorage like this:
export function localStorageSyncReducer(reducer: ActionReducer<any>): ActionReducer<any> { return localStorageSync({ keys: ['state'], rehydrate: true })(reducer); }

Now in my localStorage I have a key 'state' whose value is a JSON object of the expected format.
When my app starts, the state is properly recovered from localStorage but it is put under "state" in my store, giving something like this:
{ state: { locations: { searchLocations: [DATA FROM LOCALSTORAGE] editLocation: {DATA FROM LOCALSTORAGE} } }, locations: { searchLocations: [EMPTY], editLocation: {null} } }

I don't understand why the object recovered from localStorage isn't set as the root level of my store.