@vovkasm/redux-persist
Version:
persist and rehydrate redux stores
3 lines (2 loc) • 9.64 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.ReduxPersist=t.ReduxPersist||{})}(this,function(t){"use strict";function e(t){var e=N.call(t,q),n=t[q];try{t[q]=void 0;var r=!0}catch(t){}var o=J.call(t);return r&&(e?t[q]=n:delete t[q]),o}function n(t){return L.call(t)}function r(t){return null==t?void 0===t?D:M:G&&G in Object(t)?e(t):n(t)}function o(t){return null!=t&&"object"==typeof t}function i(t){if(!o(t)||r(t)!=U)return!1;var e=H(t);if(null===e)return!0;var n=V.call(e,"constructor")&&e.constructor;return"function"==typeof n&&n instanceof n&&Q.call(n)==W}function u(t){return!!t&&("object"===(void 0===t?"undefined":X(t))&&("function"!=typeof t.asMutable&&!!i(t)))}function c(){function t(t){var r=!1,o=[];return function(i,u){if(u.type!==E)return e.log&&!r&&o.push(u),t(i,u);e.log&&!r&&f(o),r=!0;var c=u.payload,s=t(i,u);return n(i,c,s,e.log)}}var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=e.stateReconciler||s;return function(e){return function(n,r,o){var i=e(t(n),r,o);return Z({},i,{replaceReducer:function(e){return i.replaceReducer(t(e))}})}}}function f(t){var e=t.slice(1);e.length>0&&console.log("\n redux-persist/autoRehydrate: %d actions were fired before rehydration completed. This can be a symptom of a race\n condition where the rehydrate action may overwrite the previously affected state. Consider running these actions\n after rehydration:\n ",e.length,e)}function s(t,e,n,r){var o=Z({},n);return Object.keys(e).forEach(function(i){if(t.hasOwnProperty(i)){if("object"===X(t[i])&&!e[i])return void(r&&console.log("redux-persist/autoRehydrate: sub state for key `%s` is falsy but initial state is an object, skipping autoRehydrate.",i));if(t[i]!==n[i])return r&&console.log("redux-persist/autoRehydrate: sub state for key `%s` modified, skipping autoRehydrate.",i),void(o[i]=n[i]);o[i]=u(e[i])&&u(t[i])?Z({},t[i],e[i]):e[i],r&&console.log("redux-persist/autoRehydrate: key `%s`, rehydrated to ",i,o[i])}}),o}function a(t){if("object"!==("undefined"==typeof window?"undefined":X(window))||!(t in window))return!1;try{var e=window[t],n="redux-persist "+t+" test";e.setItem(n,"test"),e.getItem(n),e.removeItem(n)}catch(t){return!1}return!0}function l(){return a("localStorage")}function d(){return a("sessionStorage")}function y(t){return"local"===t?l()?window.localStorage:{getItem:et,setItem:et,removeItem:et,getAllKeys:et}:"session"===t?d()?window.sessionStorage:{getItem:et,setItem:et,removeItem:et,getAllKeys:et}:void 0}function p(t,e){var n=t.storage,r=void 0!==t.keyPrefix?t.keyPrefix:A;if(Array.isArray(t))throw Error("redux-persist: purgeStoredState requires config as a first argument (found array). An array of keys is the optional second argument.");if(!n)throw Error("redux-persist: config.storage required in purgeStoredState");return void 0===e?new Promise(function(e,o){n.getAllKeys(function(n,i){n?o(n):e(p(t,i.filter(function(t){return 0===t.indexOf(r)}).map(function(t){return t.slice(r.length)})))})}):Promise.all(e.map(function(t){return n.removeItem(""+r+t,g(t))}))}function g(t){return function(t){}}function h(t,e){function n(t){var e=[];return j(t,function(n,r){if(i(r)){var o=k(t,r);k(R,r)!==o&&e.push(r)}}),e}function r(t,e){var n=c(e),r=k(t,e),o=d.reduce(function(t,n){return n.in(t,e)},r);return void 0===o?null:P.setItem(n,f(o),v(e))}function o(){var e=t.getState(),n=K.map(function(t){return r(e,t)});return K.splice(0),n}function i(t){return(!l||-1!==l.indexOf(t))&&-1===a.indexOf(t)}function u(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r={};return n.serial?j(e,function(t,e){try{var n=s(t),o=d.reduceRight(function(t,n){return n.out(t,e)},n);r=I(r,e,o)}catch(t){}}):r=e,t.dispatch(x(r)),r}function c(t){return""+g+t}var f=!1===e.serialize?function(t){return t}:m,s=!1===e.serialize?function(t){return t}:b,a=e.blacklist||[],l=e.whitelist||!1,d=e.transforms||[],y=e.debounce||!1,g=void 0!==e.keyPrefix?e.keyPrefix:A,h=e._stateInit||{},j=e._stateIterator||O,k=e._stateGetter||S,I=e._stateSetter||w,P=e.storage||nt("local");P.keys&&!P.getAllKeys&&(P.getAllKeys=P.keys);var R=h,E=!1,K=[],T=null;return t.subscribe(function(){if(!E){var e=t.getState();n(e).forEach(function(t){-1===K.indexOf(t)&&K.push(t)});var o=K.length;null===T&&(T=setInterval(function(){if(E&&o===K.length||0===K.length)return clearInterval(T),void(T=null);var t=K.shift();r(e,t)},y)),R=e}}),{rehydrate:u,pause:function(){E=!0},resume:function(){E=!1},purge:function(t){return p({storage:P,keyPrefix:g},t)},flush:o}}function v(t){return function(t){}}function m(t){return rt(t,null,null,function(t,e){throw Error('\n redux-persist: cannot process cyclical state.\n Consider changing your state structure to have no cycles.\n Alternatively blacklist the corresponding reducer key.\n Cycle encounted at key "'+t+'" with value "'+e+'".\n ')})}function b(t){return JSON.parse(t)}function x(t){return{type:E,payload:t}}function O(t,e){return Object.keys(t).forEach(function(n){return e(t[n],n)})}function S(t,e){return t[e]}function w(t,e,n){return t[e]=n,t}function j(t,e){function n(t){return!(!o||-1!==o.indexOf(t))||!(!i||-1===i.indexOf(t))}var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},o=r.whitelist||null,i=r.blacklist||null;return{in:function(e,r){return!n(r)&&t?t(e,r):e},out:function(t,r){return!n(r)&&e?e(t,r):t}}}function k(t,e){function n(t,e){var n=null;try{var r=c(e);n=a.reduceRight(function(e,n){return n.out(e,t)},r)}catch(t){}return n}function r(t,n){e(t,n)}function o(t){return(!s||-1!==s.indexOf(t))&&-1===f.indexOf(t)}function i(t){return""+l+t}var u=t.storage||nt("local"),c=!1===t.serialize?function(t){return t}:I,f=t.blacklist||[],s=t.whitelist||!1,a=t.transforms||[],l=void 0!==t.keyPrefix?t.keyPrefix:A;u.keys&&!u.getAllKeys&&(u=Z({},u,{getAllKeys:u.keys}));var d={},y=0;if(u.getAllKeys(function(t,e){t&&r(t);var c=e.filter(function(t){return 0===t.indexOf(l)}).map(function(t){return t.slice(l.length)}),f=c.filter(o),s=f.length;0===s&&r(null,d),f.forEach(function(t){u.getItem(i(t),function(e,o){d[t]=n(t,o),(y+=1)===s&&r(null,d)})})}),"function"!=typeof e&&Promise)return new Promise(function(t,n){e=function(e,r){e?n(e):t(r)}})}function I(t){return JSON.parse(t)}function P(t){function e(t,e){u.resume(),r&&r(t,e)}var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments[2],o=!n.skipRestore,i=null,u=h(t,n);return u.pause(),tt(o?function(){k(n,function(n,r){if(n)return void e(n);i&&("*"===i?r={}:i.forEach(function(t){return delete r[t]}));try{t.dispatch(R(r,n))}finally{e(n,r)}})}:e),Z({},u,{purge:function(t){return i=t||"*",u.purge(t)}})}function R(t){return{type:E,payload:t,error:arguments.length>1&&void 0!==arguments[1]?arguments[1]:null}}var A="reduxPersist:",E="persist/REHYDRATE",K="object"==typeof global&&global&&global.Object===Object&&global,T="object"==typeof self&&self&&self.Object===Object&&self,_=K||T||Function("return this")(),C=_.Symbol,z=Object.prototype,N=z.hasOwnProperty,J=z.toString,q=C?C.toStringTag:void 0,F=Object.prototype,L=F.toString,M="[object Null]",D="[object Undefined]",G=C?C.toStringTag:void 0,H=function(t,e){return function(n){return t(e(n))}}(Object.getPrototypeOf,Object),U="[object Object]",Y=Function.prototype,B=Object.prototype,Q=Y.toString,V=B.hasOwnProperty,W=Q.call(Object),X="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Z=Object.assign||function(t){for(var e=1;arguments.length>e;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},$="undefined"!=typeof global&&void 0!==global.setImmediate,tt=$?function(t,e){return global.setImmediate(t,e)}:function(t,e){return setTimeout(t,e)},et=function(){return null},nt=function(t,e){var n=y(t);return{getAllKeys:function(t){return new Promise(function(e,r){try{for(var o=[],i=0;n.length>i;i++)o.push(n.key(i));tt(function(){t&&t(null,o),e(o)})}catch(e){t&&t(e),r(e)}})},getItem:function(t,e){return new Promise(function(r,o){try{var i=n.getItem(t);tt(function(){e&&e(null,i),r(i)})}catch(t){e&&e(t),o(t)}})},setItem:function(t,e,r){return new Promise(function(o,i){try{n.setItem(t,e),tt(function(){r&&r(null),o()})}catch(t){r&&r(t),i(t)}})},removeItem:function(t,e){return new Promise(function(r,o){try{n.removeItem(t),tt(function(){e&&e(null),r()})}catch(t){e&&e(t),o(t)}})}}},rt=function(t,e){return e={exports:{}},t(e,e.exports),e.exports}(function(t,e){function n(t,e,n,o){return JSON.stringify(t,r(e,o),n)}function r(t,e){var n=[],r=[];return null==e&&(e=function(t,e){return n[0]===e?"[Circular ~]":"[Circular ~."+r.slice(0,n.indexOf(e)).join(".")+"]"}),function(o,i){if(n.length>0){var u=n.indexOf(this);~u?n.splice(u+1):n.push(this),~u?r.splice(u,1/0,o):r.push(o),~n.indexOf(i)&&(i=e.call(this,o,i))}else n.push(i);return null==t?i:t.call(this,o,i)}}e=t.exports=n,e.getSerialize=r}),ot=function(t,e,n){console.error('redux-persist: this method of importing storages has been removed. instead use `import { asyncLocalStorage } from "redux-persist/storages"`'),"function"==typeof t&&t(),"function"==typeof e&&e(),"function"==typeof n&&n()},it={getAllKeys:ot,getItem:ot,setItem:ot,removeItem:ot},ut={asyncLocalStorage:it,asyncSessionStorage:it};t.autoRehydrate=c,t.createPersistor=h,t.createTransform=j,t.getStoredState=k,t.persistStore=P,t.purgeStoredState=p,t.storages=ut,Object.defineProperty(t,"__esModule",{value:!0})});
//# sourceMappingURL=redux-persist.min.js.map