all files / src/reducer/ index.js

100% Statements 6/6
100% Branches 2/2
100% Functions 3/3
100% Lines 5/5
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23                                   
import { combineReducers } from 'redux';
import isEmpty from 'lodash/isEmpty';
import { enableBatching } from 'redux-batched-actions';
 
import createEntityReducer from './entity';
 
 
function createReducer(schemas) {
  const entitiesReducers = Object.keys(schemas).reduce((memo, k) => ({
    ...memo,
    [k]: createEntityReducer(schemas[k]),
  }), {});
  return combineReducers(entitiesReducers);
}
 
 
export default function entities(schemas) {
  if (isEmpty(schemas)) {
    throw new Error('[INVALID SCHEMAS]');
  }
  return enableBatching(createReducer(schemas));
}