import { ActionReducer , INIT , MetaReducer , UPDATE } from '@ngrx/store' ; import { LocalStorageService } from '@nx-mean-starter/shared' ; import { State } from './reducer' ; export function initStateFromLocalStorage ( reducer ) { return function ( state , action ) { const newState = reducer ( state , action ) ; if ( [ INIT . toString ( ) , UPDATE . toString ( ) ] . includes ( action . type ) ) { return { ... newState , ... LocalStorageService . loadInitialState ( ) } ; } return newState ; } ; } export const metaReducers = [ initStateFromLocalStorage ] ;