ngrx-store-localstorage icon indicating copy to clipboard operation
ngrx-store-localstorage copied to clipboard

not syncing with local storage for feature module

Open santhoshrajuvysyaraju opened this issue 6 years ago • 3 comments

Hi ,

i have tried to sync the store with following code. but it is not synching.

Please see the code.

export function localStorageSyncReducer(reducer: ActionReducer<any>): ActionReducer<any> {
  return localStorageSync({keys: ['adminState'], rehydrate: true })(reducer);
}
const metaReducers: Array<MetaReducer<any, any>> = [localStorageSyncReducer];

here is my call in imports.

 StoreModule.forFeature('adminState',userReducer,{ metaReducers }),
     EffectsModule.forFeature([AdminEffects])

the main problem is it is not giving any error. it is not synching the store with local storage tried using feature module.

but it is fine working in root module.

help me to solve the issue.

santhoshrajuvysyaraju avatar Jun 26 '18 13:06 santhoshrajuvysyaraju

Try passing an initial state to the third argument

StoreModule.forFeature('adminState', userReducer, { initialState: {}, metaReducers }),

or to the forRoot module.

...
StoreModule.forRoot({}),
StoreModule.forFeature('adminState', userReducer, { metaReducers }),
...

ernestomancebo avatar Aug 17 '18 15:08 ernestomancebo

@santhoshrajuvysyaraju

Did you ever figure this out? I am running into the same issue, I believe it is just a configuration issue. But the localStorageSync is never being called for feature modules/stores, but the root module/store is working as expected.

broot02 avatar Oct 11 '19 16:10 broot02

Hello, I just created a PR to address this issue: https://github.com/btroncone/ngrx-store-localstorage/pull/249

Can you please check and review if it suffices.

Abhirocks889 avatar May 12 '23 09:05 Abhirocks889