auth0-extensions/auth0-delegated-administration-extension

View on GitHub
client/utils/createReducer.js

Summary

Maintainability
A
0 mins
Test Coverage
import Immutable, { Map, List } from 'immutable';

export default function createReducer(initialState, actionHandlers) {
  return (state = initialState, action) => {
    if (!Map.isMap(state) && !List.isList(state)) {
      state = Immutable.fromJS(state);
    }

    const handler = actionHandlers[action.type];
    if (!handler) {
      return state;
    }

    state = handler(state, action);
    if (!Map.isMap(state) && !List.isList(state)) {
      throw new TypeError('Reducers must return Immutable objects.');
    }

    return state;
  };
}