demo/script/main.js
function combineReducers(reducers) {
  var reducerKeys = Object.keys(reducers);
  var finalReducers = {};
  for (var i = 0; i < reducerKeys.length; i++) {
    var key = reducerKeys[i];

    if (process.env.NODE_ENV !== 'production') {
      if (typeof reducers[key] === 'undefined') {
        (0, _warning2.default)('No reducer provided for key "' + key + '"');
      }
    }

    if (typeof reducers[key] === 'function') {
      finalReducers[key] = reducers[key];
    }
  }
  var finalReducerKeys = Object.keys(finalReducers);

  var unexpectedKeyCache = void 0;
  if (process.env.NODE_ENV !== 'production') {
    unexpectedKeyCache = {};
  }

  var shapeAssertionError = void 0;
  try {
    assertReducerShape(finalReducers);
  } catch (e) {
    shapeAssertionError = e;
  }

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

    if (shapeAssertionError) {
      throw shapeAssertionError;
    }

    if (process.env.NODE_ENV !== 'production') {
      var warningMessage = getUnexpectedStateShapeWarningMessage(state, finalReducers, action, unexpectedKeyCache);
      if (warningMessage) {
        (0, _warning2.default)(warningMessage);
      }
    }

    var hasChanged = false;
    var nextState = {};
    for (var _i = 0; _i < finalReducerKeys.length; _i++) {
      var _key = finalReducerKeys[_i];
      var reducer = finalReducers[_key];
      var previousStateForKey = state[_key];
      var nextStateForKey = reducer(previousStateForKey, action);
      if (typeof nextStateForKey === 'undefined') {
        var errorMessage = getUndefinedStateErrorMessage(_key, action);
        throw new Error(errorMessage);
      }
      nextState[_key] = nextStateForKey;
      hasChanged = hasChanged || nextStateForKey !== previousStateForKey;
    }
    return hasChanged ? nextState : state;
  };
}
function combineReducers(reducers) {
  var reducerKeys = Object.keys(reducers);
  var finalReducers = {};
  for (var i = 0; i < reducerKeys.length; i++) {
    var key = reducerKeys[i];

    if (process.env.NODE_ENV !== 'production') {
      if (typeof reducers[key] === 'undefined') {
        (0, _warning2.default)('No reducer provided for key "' + key + '"');
      }
    }

    if (typeof reducers[key] === 'function') {
      finalReducers[key] = reducers[key];
    }
  }
  var finalReducerKeys = Object.keys(finalReducers);

  var unexpectedKeyCache = void 0;
  if (process.env.NODE_ENV !== 'production') {
    unexpectedKeyCache = {};
  }

  var shapeAssertionError = void 0;
  try {
    assertReducerShape(finalReducers);
  } catch (e) {
    shapeAssertionError = e;
  }

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

    if (shapeAssertionError) {
      throw shapeAssertionError;
    }

    if (process.env.NODE_ENV !== 'production') {
      var warningMessage = getUnexpectedStateShapeWarningMessage(state, finalReducers, action, unexpectedKeyCache);
      if (warningMessage) {
        (0, _warning2.default)(warningMessage);
      }
    }

    var hasChanged = false;
    var nextState = {};
    for (var _i = 0; _i < finalReducerKeys.length; _i++) {
      var _key = finalReducerKeys[_i];
      var reducer = finalReducers[_key];
      var previousStateForKey = state[_key];
      var nextStateForKey = reducer(previousStateForKey, action);
      if (typeof nextStateForKey === 'undefined') {
        var errorMessage = getUndefinedStateErrorMessage(_key, action);
        throw new Error(errorMessage);
      }
      nextState[_key] = nextStateForKey;
      hasChanged = hasChanged || nextStateForKey !== previousStateForKey;
    }
    return hasChanged ? nextState : state;
  };
}
function combineReducers ( reducers ) { var reducerKeys = Object . keys ( reducers ) ; var finalReducers = { } ; for ( var i = 0 ; i < reducerKeys . length ; i ++ ) { var key = reducerKeys [ i ] ; if ( process . env . NODE_ENV !== 'production' ) { if ( typeof reducers [ key ] === 'undefined' ) { ( 0 , _warning2 . default ) ( 'No reducer provided for key "' + key + '"' ) ; } } if ( typeof reducers [ key ] === 'function' ) { finalReducers [ key ] = reducers [ key ] ; } } var finalReducerKeys = Object . keys ( finalReducers ) ; var unexpectedKeyCache = void 0 ; if ( process . env . NODE_ENV !== 'production' ) { unexpectedKeyCache = { } ; } var shapeAssertionError = void 0 ; try { assertReducerShape ( finalReducers ) ; } catch ( e ) { shapeAssertionError = e ; } return function combination ( ) { var state = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : { } ; var action = arguments [ 1 ] ; if ( shapeAssertionError ) { throw shapeAssertionError ; } if ( process . env . NODE_ENV !== 'production' ) { var warningMessage = getUnexpectedStateShapeWarningMessage ( state , finalReducers , action , unexpectedKeyCache ) ; if ( warningMessage ) { ( 0 , _warning2 . default ) ( warningMessage ) ; } } var hasChanged = false ; var nextState = { } ; for ( var _i = 0 ; _i < finalReducerKeys . length ; _i ++ ) { var _key = finalReducerKeys [ _i ] ; var reducer = finalReducers [ _key ] ; var previousStateForKey = state [ _key ] ; var nextStateForKey = reducer ( previousStateForKey , action ) ; if ( typeof nextStateForKey === 'undefined' ) { var errorMessage = getUndefinedStateErrorMessage ( _key , action ) ; throw new Error ( errorMessage ) ; } nextState [ _key ] = nextStateForKey ; hasChanged = hasChanged || nextStateForKey !== previousStateForKey ; } return hasChanged ? nextState : state ; } ; }
Turns an object whose values are different reducer functions, into a single
reducer function. It will call every child reducer, and gather their results
into a single state object, whose keys correspond to the keys of the passed
reducer functions.

@param {Object} reducers An object whose values correspond to different
reducer functions that need to be combined into one. One handy way to obtain
it is to use ES6 `import * as reducers` syntax. The reducers may never return
undefined for any action. Instead, they should return their initial state
if the state passed to them was undefined, and the current state for any
unrecognized action.

@returns {Function} A reducer function that invokes every reducer inside the
passed object, and builds a state object with the same shape.
Turns an object whose values are different reducer functions into a single reducer function . It will call every child reducer and gather their results into a single state object whose keys correspond to the keys of the passed reducer functions .