text: "use strict";
  
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  
  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  exports.default = exports.onSubKey = void 0;
  
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
  
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  
  /**
   * Higher-order reducer creator which creates a combined reducer object, keyed
   * by a property on the action object.
   *
   * @param {string} actionProperty Action property by which to key object.
   *
   * @return {Function} Higher-order reducer.
   */
  var onSubKey = function onSubKey(actionProperty) {
    return function (reducer) {
      return function () {
        var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
        var action = arguments.length > 1 ? arguments[1] : undefined;
        // Retrieve subkey from action. Do not track if undefined; useful for cases
        // where reducer is scoped by action shape.
        var key = action[actionProperty];
  
        if (key === undefined) {
          return state;
        } // Avoid updating state if unchanged. Note that this also accounts for a
        // reducer which returns undefined on a key which is not yet tracked.
  
  
        var nextKeyState = reducer(state[key], action);
  
        if (nextKeyState === state[key]) {
          return state;
        }
  
        return _objectSpread(_objectSpread({}, state), {}, (0, _defineProperty2.default)({}, key, nextKeyState));
      };
    };
  };
  
  exports.onSubKey = onSubKey;
  var _default = onSubKey;
  exports.default = _default;
  //# sourceMappingURL=on-sub-key.js.map