loading...

NGRX Workshop Notes - Meta-Reducers

alfredoperez profile image Alfredo Perez ・1 min read

NGRX-Workshop-NOTES (9 Part Series)

1) NGRX Workshop Notes - Introduction 2) NGRX Workshop Notes - Actions 3 ... 7 3) NGRX Workshop Notes - Reducers 4) NGRX Workshop Notes - Selectors 5) NGRX Workshop Notes - Effects 6) NGRX Workshop Notes - Entity 7) NGRX Workshop Notes - Meta-Reducers 8) NGRX Workshop Notes - Folder Structure 9) NGRX Workshop Notes - Other links
  • Intercept actions before they are reduced
  • Intercept state before it is emitted
  • Can change the control flow of the Store

Alt Text

Most common use cases

  • Reset state when a signout action occurs
  • for debugging creating logger
  • to rehydrate when the application starts up

-It is like a plugin system for the store, they behave similarly to the interceptors

Example

An example of this can be to use it in a logger

const logger = (reducer: ActionReducer<any, any>) => (state: any, action: Action) => {
    console.log('Previous State', state);
    console.log('Action', action);

    const nextState = reducer(state, action);

    console.log('Next State', nextState);
    return nextState;
};

export const metaReducers: MetaReducer<State>[] = [logger];

Discussion

markdown guide