lib/index.js
function makePrefixMapReducer() {
  for (var _len2 = arguments.length, reducers = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
    reducers[_key2] = arguments[_key2];
  }

  if (reducers.some(function (r) {
    return !_lodash2.default.isFunction(r);
  })) {
    throw new Error('all arguments must be a function');
  }

  var initAction = { type: '@@redux/INIT' };
  var initialState = reducers.reduce(function (a, r) {
    return Object.assign(a, r(undefined, initAction));
  }, {});

  function prefixOf(r, i) {
    // TODO warning about foreign reducers
    var p = _lodash2.default.isFunction(r.getPrefix) ? r.getPrefix() : '@@FOREIGN' + i;
    if (p && p.charAt(p.length - 1) === '/') {
      return p.substr(0, p.length - 1);
    }
    return p;
  }

  var reducerMap = reducers.reduce(function (a, r, i) {
    return _extends({}, a, _defineProperty({}, prefixOf(r, i), r));
  }, {});

  var reducer = function reducer() {
    var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initialState;
    var action = arguments[1];

    var i = action.type.indexOf('/');
    var prefix = i >= 0 ? action.type.substring(0, i) : '';
    if (prefix) {
      var fn = reducerMap[prefix];
      return fn(state, action);
    }
    // TODO try to dispatch foreign reducers
    return state;
  };

  reducer.getInitialState = function getInitialState() {
    return _extends({}, initialState);
  };

  return reducer;
}
function makePrefixMapReducer() {
  for (var _len2 = arguments.length, reducers = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
    reducers[_key2] = arguments[_key2];
  }

  if (reducers.some(function (r) {
    return !_lodash2.default.isFunction(r);
  })) {
    throw new Error('all arguments must be a function');
  }

  var initAction = { type: '@@redux/INIT' };
  var initialState = reducers.reduce(function (a, r) {
    return Object.assign(a, r(undefined, initAction));
  }, {});

  function prefixOf(r, i) {
    // TODO warning about foreign reducers
    var p = _lodash2.default.isFunction(r.getPrefix) ? r.getPrefix() : '@@FOREIGN' + i;
    if (p && p.charAt(p.length - 1) === '/') {
      return p.substr(0, p.length - 1);
    }
    return p;
  }

  var reducerMap = reducers.reduce(function (a, r, i) {
    return _extends({}, a, _defineProperty({}, prefixOf(r, i), r));
  }, {});

  var reducer = function reducer() {
    var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initialState;
    var action = arguments[1];

    var i = action.type.indexOf('/');
    var prefix = i >= 0 ? action.type.substring(0, i) : '';
    if (prefix) {
      var fn = reducerMap[prefix];
      return fn(state, action);
    }
    // TODO try to dispatch foreign reducers
    return state;
  };

  reducer.getInitialState = function getInitialState() {
    return _extends({}, initialState);
  };

  return reducer;
}
function makePrefixMapReducer ( ) { for ( var _len2 = arguments . length , reducers = Array ( _len2 ) , _key2 = 0 ; _key2 < _len2 ; _key2 ++ ) { reducers [ _key2 ] = arguments [ _key2 ] ; } if ( reducers . some ( function ( r ) { return ! _lodash2 . default . isFunction ( r ) ; } ) ) { throw new Error ( 'all arguments must be a function' ) ; } var initAction = { type : '@@redux/INIT' } ; var initialState = reducers . reduce ( function ( a , r ) { return Object . assign ( a , r ( undefined , initAction ) ) ; } , { } ) ; function prefixOf ( r , i ) { // TODO warning about foreign reducers var p = _lodash2 . default . isFunction ( r . getPrefix ) ? r . getPrefix ( ) : '@@FOREIGN' + i ; if ( p && p . charAt ( p . length - 1 ) === '/' ) { return p . substr ( 0 , p . length - 1 ) ; } return p ; } var reducerMap = reducers . reduce ( function ( a , r , i ) { return _extends ( { } , a , _defineProperty ( { } , prefixOf ( r , i ) , r ) ) ; } , { } ) ; var reducer = function reducer ( ) { var state = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : initialState ; var action = arguments [ 1 ] ; var i = action . type . indexOf ( '/' ) ; var prefix = i >= 0 ? action . type . substring ( 0 , i ) : '' ; if ( prefix ) { var fn = reducerMap [ prefix ] ; return fn ( state , action ) ; } // TODO try to dispatch foreign reducers return state ; } ; reducer . getInitialState = function getInitialState ( ) { return _extends ( { } , initialState ) ; } ; return reducer ; }
Combines reducers into reducer that dispatches action to appropriate reducer depending on action type prefix.
@param  {functions} ...reducers List of reducer functions to dispatch.
@return {function} A reducer function that dispatches action to appropriate reducer depending on action type prefix.
Combines reducers into reducer that dispatches action to appropriate reducer depending on action type prefix .