angular-hmr
angular-hmr copied to clipboard
ngrx tutorial is not full
Hello. I spend about half of day and still can't get positive result. State data is not saved after reload. Please provide normal example of usage.
I already tried:
- Your repo tutorial
- https://medium.com/@beeman/tutorial-enable-hmr-in-angular-cli-apps-1b0d13b80130
- https://stackoverflow.com/a/48221333/4357871
- https://github.com/gdi2290/angular-hmr/pull/66#issuecomment-384275692
Came up with this, seems to work
export function stateSetter(reducer: ActionReducer<any>): ActionReducer<any> {
return function (state: any, action: any) {
const NGRX_STATE = '___NGRX_STATE___';
const newState = reducer(state, action);
if (action.type !== '@ngrx/store/init') {
return window[NGRX_STATE] = newState;
} else {
if (window[NGRX_STATE]) {
return window[NGRX_STATE];
}
return newState;
}
};
}
export const metaReducers: MetaReducer<State>[] = !environment.production ? [storeFreeze, stateSetter] : [];