"use strict"; exports.__esModule = true; var _exportNames = { rememberReducer: true, rememberEnhancer: true, REMEMBER_REHYDRATED: true, REMEMBER_PERSISTED: true }; exports.rememberReducer = exports.rememberEnhancer = void 0; var _init = _interopRequireDefault(require("./init.cjs")); var _actionTypes = require("./action-types.cjs"); exports.REMEMBER_REHYDRATED = _actionTypes.REMEMBER_REHYDRATED; exports.REMEMBER_PERSISTED = _actionTypes.REMEMBER_PERSISTED; var _redux = require("redux"); var _errors = require("./errors.cjs"); Object.keys(_errors).forEach(function (key) { if (key === "default" || key === "__esModule") return; if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; if (key in exports && exports[key] === _errors[key]) return; exports[key] = _errors[key]; }); var _types = require("./types.cjs"); Object.keys(_types).forEach(function (key) { if (key === "default" || key === "__esModule") return; if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; if (key in exports && exports[key] === _types[key]) return; exports[key] = _types[key]; }); function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; } function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } var rememberReducer = exports.rememberReducer = function rememberReducer(reducer) { var data = { state: {} }; return function (state, action) { var _action$type; if (state === void 0) { state = data.state; } if (action.type && ((action == null ? void 0 : action.type) === '@@INIT' || action != null && (_action$type = action.type) != null && _action$type.startsWith('@@redux/INIT'))) { data.state = _objectSpread({}, state); } var rootReducer = typeof reducer === 'function' ? reducer : (0, _redux.combineReducers)(reducer); switch (action.type) { case _actionTypes.REMEMBER_REHYDRATED: { var rehydratedState = _objectSpread(_objectSpread({}, data.state), (action == null ? void 0 : action.payload) || {}); data.state = rootReducer(rehydratedState, { type: _actionTypes.REMEMBER_REHYDRATED, payload: rehydratedState }); return data.state; } default: return rootReducer(state, action); } }; }; var rememberEnhancer = exports.rememberEnhancer = function rememberEnhancer(driver, rememberedKeys, _temp) { var _ref = _temp === void 0 ? {} : _temp, _ref$prefix = _ref.prefix, prefix = _ref$prefix === void 0 ? '@@remember-' : _ref$prefix, _ref$serialize = _ref.serialize, serialize = _ref$serialize === void 0 ? function (data, key) { return JSON.stringify(data); } : _ref$serialize, _ref$unserialize = _ref.unserialize, unserialize = _ref$unserialize === void 0 ? function (data, key) { return JSON.parse(data); } : _ref$unserialize, _ref$persistThrottle = _ref.persistThrottle, persistThrottle = _ref$persistThrottle === void 0 ? 100 : _ref$persistThrottle, persistDebounce = _ref.persistDebounce, _ref$persistWholeStor = _ref.persistWholeStore, persistWholeStore = _ref$persistWholeStor === void 0 ? false : _ref$persistWholeStor, initActionType = _ref.initActionType, _ref$errorHandler = _ref.errorHandler, errorHandler = _ref$errorHandler === void 0 ? console.warn : _ref$errorHandler; var storeCreator = function storeCreator(createStore) { return function (rootReducer, preloadedState, enhancer) { var isInitialized = false; var initialize = function initialize(store) { return (0, _init["default"])(store, rememberedKeys, { driver: driver, prefix: prefix, serialize: serialize, unserialize: unserialize, persistThrottle: persistThrottle, persistDebounce: persistDebounce, persistWholeStore: persistWholeStore, errorHandler: errorHandler }); }; var store = createStore(function (state, action) { if (!isInitialized && initActionType && action.type === initActionType) { isInitialized = true; setTimeout(function () { return initialize(store); }, 0); } return rootReducer(state, action); }, preloadedState, enhancer); if (!initActionType) { isInitialized = true; initialize(store); } return store; }; }; return storeCreator; }; //# sourceMappingURL=index.cjs.map