UNPKG

higher-order-reducers

Version:

A library of simple everyday reducer utility functions

25 lines (21 loc) 692 B
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var compose = function compose() { var reducers = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; if (!Array.isArray(reducers)) { throw new Error('"reducers" must be an array'); } for (var i = 0; i < reducers.length; i += 1) { if (typeof reducers[i] !== 'function') { throw new Error('Element at position ' + i + ' in "compose" is not a reducer'); } } return function (state, action) { return reducers.reduce(function (currentState, currentReducer) { return currentReducer(currentState, action); }, state); }; }; exports.default = compose;