Skip to content
Snippets Groups Projects
app.metareducers.ts 956 B
Newer Older
import { isNotEmpty } from './shared/empty.util';
import { StoreActionTypes } from './store.actions';

Art Lowel's avatar
Art Lowel committed
// fallback ngrx debugger
let actionCounter = 0;

export function debugMetaReducer(reducer) {
  return (state, action) => {
    actionCounter++;
    console.log('@ngrx action', actionCounter, action.type);
    console.log('state', JSON.stringify(state));
    console.log('action', JSON.stringify(action));
    console.log('------------------------------------');
    return reducer(state, action);
  }
}

export function universalMetaReducer(reducer) {
  return (state, action) => {
    switch (action.type) {
      case StoreActionTypes.REHYDRATE:
        state = Object.assign({}, state, action.payload);
        break;
      case StoreActionTypes.REPLAY:
      default:
Art Lowel's avatar
Art Lowel committed
        break;
Art Lowel's avatar
Art Lowel committed
    return reducer(state, action);
export const debugMetaReducers = [
  debugMetaReducer
];

Art Lowel's avatar
Art Lowel committed
export const appMetaReducers = [
Art Lowel's avatar
Art Lowel committed
];