autoMergeLevel1.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  2. 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; }
  3. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  4. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  5. /*
  6. autoMergeLevel1:
  7. - merges 1 level of substate
  8. - skips substate if already modified
  9. */
  10. export default function autoMergeLevel1(inboundState, originalState, reducedState, _ref) {
  11. var debug = _ref.debug;
  12. var newState = _objectSpread({}, reducedState); // only rehydrate if inboundState exists and is an object
  13. if (inboundState && _typeof(inboundState) === 'object') {
  14. Object.keys(inboundState).forEach(function (key) {
  15. // ignore _persist data
  16. if (key === '_persist') return; // if reducer modifies substate, skip auto rehydration
  17. if (originalState[key] !== reducedState[key]) {
  18. if (process.env.NODE_ENV !== 'production' && debug) console.log('redux-persist/stateReconciler: sub state for key `%s` modified, skipping.', key);
  19. return;
  20. } // otherwise hard set the new value
  21. newState[key] = inboundState[key];
  22. });
  23. }
  24. if (process.env.NODE_ENV !== 'production' && debug && inboundState && _typeof(inboundState) === 'object') console.log("redux-persist/stateReconciler: rehydrated keys '".concat(Object.keys(inboundState).join(', '), "'"));
  25. return newState;
  26. }