Skip to content

Instantly share code, notes, and snippets.

@itayod
Last active June 16, 2019 13:31
Show Gist options
  • Save itayod/5ad2c3d3646877176992e2e5c6b8b4ed to your computer and use it in GitHub Desktop.
Save itayod/5ad2c3d3646877176992e2e5c6b8b4ed to your computer and use it in GitHub Desktop.
import {StoreModule, MetaReducer, META_REDUCERS} from '@ngrx/store';
import {ROOT_STORAGE_KEYS, LOCAL_STORAGE_KEY} from './app.tokens';
import {LocalStorageService} from './shared/local-storage.service';
import {storageMetaReducer} from './storage.metareducer';
// factory meta-reducer configuration function
export function getMetaReducers(saveKeys: string[],
localStorageKey: string,
storageService: LocalStorageService
): MetaReducer<any>[] {
return [storageMetaReducer(saveKeys, localStorageKey, storageService)];
}
@NgModule({
imports : [
StoreModule.forRoot(reducers)
],
providers: [
{provide: ROOT_STORAGE_KEYS, useValue: ['layout.theme']},
{provide: ROOT_LOCAL_STORAGE_KEY, useValue: '__app_storage__'},
{
provide : META_REDUCERS,
deps : [ROOT_STORAGE_KEYS, ROOT_LOCAL_STORAGE_KEY, LocalStorageService],
useFactory: getMetaReducers
},
]
})
export class AppModule {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment