Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
export function productSync(reducer: ActionReducer<{ product: ProductState }>) {
return (state, action) => {
let reducedState = reducer(state, action);
if (action.type === INIT) {
const data = window.localStorage.getItem('productData');
if (data) {
reducedState = {
...reducedState,
product: JSON.parse(data),
};
}
} else if (action.type !== UPDATE) {
window.localStorage.setItem(
'productData',
JSON.stringify(reducedState.product)
);
}
return reducedState;
};
}
@NgModule({
imports: [
StoreModule.forRoot(
{ product: productReducer },
{ metaReducers: [productSync] }
),
],
})
export class SomeModule {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.