Spartacus : Clear/Reset State on Logout
This can be done using meta reducers.
Below example is for clearing multicartstate after user logs out.
1. MultiCartStoreModule configuration to define metareducres (multiCartMetaReducers)
@NgModule({
imports: [
CommonModule,
StateModule,
StoreModule.forFeature(MULTI_CART_FEATURE, multiCartReducerToken, {
metaReducers: multiCartMetaReducers,
}),
EffectsModule.forFeature(effects),
],
providers: [multiCartReducerProvider],
})
export class MultiCartStoreModule {}
2. clearMultiCartState function to Define multiCartMetaReducers
export function clearMultiCartState(
reducer: ActionReducer<any>
): ActionReducer<any> {
return function (state, action) {
if (action.type === AuthActions.LOGOUT) {
state = undefined;
}
return reducer(state, action);
};
}
export const multiCartMetaReducers: MetaReducer<any>[] = [clearMultiCartState];
Comments
Post a Comment