parent
0373873b7d
commit
962e6f4137
204 changed files with 9530 additions and 1 deletions
File diff suppressed because one or more lines are too long
@ -0,0 +1 @@ |
||||
{"ast":null,"code":"import { createStore, applyMiddleware, combineReducers } from \"redux\";\nimport { composeWithDevTools } from \"redux-devtools-extension\";\nimport { persistStore, persistReducer } from \"redux-persist\"; // import * as reducers from \"./reducers\";\n\nimport thunk from \"redux-thunk\";\nimport storage from \"redux-persist/lib/storage\"; // defaults to localStorage for web\n\nconst persistConfig = {\n key: \"root\",\n storage\n};\nconst initialState = {};\nconst middleware = [thunk];\nconst persistedReducer = persistReducer(persistConfig, combineReducers(reducers));\nexport default (() => {\n let store = createStore(persistedReducer, initialState, composeWithDevTools(applyMiddleware(...middleware)));\n const persistor = persistStore(store);\n return {\n store,\n persistor\n };\n});","map":{"version":3,"names":["createStore","applyMiddleware","combineReducers","composeWithDevTools","persistStore","persistReducer","thunk","storage","persistConfig","key","initialState","middleware","persistedReducer","reducers","store","persistor"],"sources":["/Users/mahdi/Documents/work/programming/barnameNegar/arbaeenWebApp/src/redux/store.js"],"sourcesContent":["import { createStore, applyMiddleware, combineReducers } from \"redux\";\nimport { composeWithDevTools } from \"redux-devtools-extension\";\nimport { persistStore, persistReducer } from \"redux-persist\";\n\n// import * as reducers from \"./reducers\";\nimport thunk from \"redux-thunk\";\nimport storage from \"redux-persist/lib/storage\"; // defaults to localStorage for web\n\nconst persistConfig = {\n key: \"root\",\n storage,\n};\n\nconst initialState = {};\nconst middleware = [thunk];\n\nconst persistedReducer = persistReducer(\n persistConfig,\n combineReducers(reducers)\n);\n\nexport default () => {\n let store = createStore(\n persistedReducer,\n initialState,\n composeWithDevTools(applyMiddleware(...middleware))\n );\n const persistor = persistStore(store);\n\n return { store, persistor };\n};\n"],"mappings":"AAAA,SAASA,WAAT,EAAsBC,eAAtB,EAAuCC,eAAvC,QAA8D,OAA9D;AACA,SAASC,mBAAT,QAAoC,0BAApC;AACA,SAASC,YAAT,EAAuBC,cAAvB,QAA6C,eAA7C,C,CAEA;;AACA,OAAOC,KAAP,MAAkB,aAAlB;AACA,OAAOC,OAAP,MAAoB,2BAApB,C,CAAiD;;AAEjD,MAAMC,aAAa,GAAG;EACpBC,GAAG,EAAE,MADe;EAEpBF;AAFoB,CAAtB;AAKA,MAAMG,YAAY,GAAG,EAArB;AACA,MAAMC,UAAU,GAAG,CAACL,KAAD,CAAnB;AAEA,MAAMM,gBAAgB,GAAGP,cAAc,CACrCG,aADqC,EAErCN,eAAe,CAACW,QAAD,CAFsB,CAAvC;AAKA,gBAAe,MAAM;EACnB,IAAIC,KAAK,GAAGd,WAAW,CACrBY,gBADqB,EAErBF,YAFqB,EAGrBP,mBAAmB,CAACF,eAAe,CAAC,GAAGU,UAAJ,CAAhB,CAHE,CAAvB;EAKA,MAAMI,SAAS,GAAGX,YAAY,CAACU,KAAD,CAA9B;EAEA,OAAO;IAAEA,KAAF;IAASC;EAAT,CAAP;AACD,CATD"},"metadata":{},"sourceType":"module"} |
||||
File diff suppressed because one or more lines are too long
@ -0,0 +1 @@ |
||||
{"ast":null,"code":"import { KEY_PREFIX } from './constants';\nexport default function purgeStoredState(config) {\n var storage = config.storage;\n var storageKey = \"\".concat(config.keyPrefix !== undefined ? config.keyPrefix : KEY_PREFIX).concat(config.key);\n return storage.removeItem(storageKey, warnIfRemoveError);\n}\n\nfunction warnIfRemoveError(err) {\n if (err && process.env.NODE_ENV !== 'production') {\n console.error('redux-persist/purgeStoredState: Error purging data stored state', err);\n }\n}","map":{"version":3,"names":["KEY_PREFIX","purgeStoredState","config","storage","storageKey","concat","keyPrefix","undefined","key","removeItem","warnIfRemoveError","err","process","env","NODE_ENV","console","error"],"sources":["/Users/mahdi/Documents/work/programming/barnameNegar/arbaeenWebApp/node_modules/redux-persist/es/purgeStoredState.js"],"sourcesContent":["import { KEY_PREFIX } from './constants';\nexport default function purgeStoredState(config) {\n var storage = config.storage;\n var storageKey = \"\".concat(config.keyPrefix !== undefined ? config.keyPrefix : KEY_PREFIX).concat(config.key);\n return storage.removeItem(storageKey, warnIfRemoveError);\n}\n\nfunction warnIfRemoveError(err) {\n if (err && process.env.NODE_ENV !== 'production') {\n console.error('redux-persist/purgeStoredState: Error purging data stored state', err);\n }\n}"],"mappings":"AAAA,SAASA,UAAT,QAA2B,aAA3B;AACA,eAAe,SAASC,gBAAT,CAA0BC,MAA1B,EAAkC;EAC/C,IAAIC,OAAO,GAAGD,MAAM,CAACC,OAArB;EACA,IAAIC,UAAU,GAAG,GAAGC,MAAH,CAAUH,MAAM,CAACI,SAAP,KAAqBC,SAArB,GAAiCL,MAAM,CAACI,SAAxC,GAAoDN,UAA9D,EAA0EK,MAA1E,CAAiFH,MAAM,CAACM,GAAxF,CAAjB;EACA,OAAOL,OAAO,CAACM,UAAR,CAAmBL,UAAnB,EAA+BM,iBAA/B,CAAP;AACD;;AAED,SAASA,iBAAT,CAA2BC,GAA3B,EAAgC;EAC9B,IAAIA,GAAG,IAAIC,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAApC,EAAkD;IAChDC,OAAO,CAACC,KAAR,CAAc,iEAAd,EAAiFL,GAAjF;EACD;AACF"},"metadata":{},"sourceType":"module"} |
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1 @@ |
||||
{"ast":null,"code":"export { default as persistReducer } from './persistReducer';\nexport { default as persistCombineReducers } from './persistCombineReducers';\nexport { default as persistStore } from './persistStore';\nexport { default as createMigrate } from './createMigrate';\nexport { default as createTransform } from './createTransform';\nexport { default as getStoredState } from './getStoredState';\nexport { default as createPersistoid } from './createPersistoid';\nexport { default as purgeStoredState } from './purgeStoredState';\nexport * from './constants';","map":{"version":3,"names":["default","persistReducer","persistCombineReducers","persistStore","createMigrate","createTransform","getStoredState","createPersistoid","purgeStoredState"],"sources":["/Users/mahdi/Documents/work/programming/barnameNegar/arbaeenWebApp/node_modules/redux-persist/es/index.js"],"sourcesContent":["export { default as persistReducer } from './persistReducer';\nexport { default as persistCombineReducers } from './persistCombineReducers';\nexport { default as persistStore } from './persistStore';\nexport { default as createMigrate } from './createMigrate';\nexport { default as createTransform } from './createTransform';\nexport { default as getStoredState } from './getStoredState';\nexport { default as createPersistoid } from './createPersistoid';\nexport { default as purgeStoredState } from './purgeStoredState';\nexport * from './constants';"],"mappings":"AAAA,SAASA,OAAO,IAAIC,cAApB,QAA0C,kBAA1C;AACA,SAASD,OAAO,IAAIE,sBAApB,QAAkD,0BAAlD;AACA,SAASF,OAAO,IAAIG,YAApB,QAAwC,gBAAxC;AACA,SAASH,OAAO,IAAII,aAApB,QAAyC,iBAAzC;AACA,SAASJ,OAAO,IAAIK,eAApB,QAA2C,mBAA3C;AACA,SAASL,OAAO,IAAIM,cAApB,QAA0C,kBAA1C;AACA,SAASN,OAAO,IAAIO,gBAApB,QAA4C,oBAA5C;AACA,SAASP,OAAO,IAAIQ,gBAApB,QAA4C,oBAA5C;AACA,cAAc,aAAd"},"metadata":{},"sourceType":"module"} |
||||
@ -0,0 +1 @@ |
||||
{"ast":null,"code":"import { combineReducers } from 'redux';\nimport persistReducer from './persistReducer';\nimport autoMergeLevel2 from './stateReconciler/autoMergeLevel2'; // combineReducers + persistReducer with stateReconciler defaulted to autoMergeLevel2\n\nexport default function persistCombineReducers(config, reducers) {\n config.stateReconciler = config.stateReconciler === undefined ? autoMergeLevel2 : config.stateReconciler;\n return persistReducer(config, combineReducers(reducers));\n}","map":{"version":3,"names":["combineReducers","persistReducer","autoMergeLevel2","persistCombineReducers","config","reducers","stateReconciler","undefined"],"sources":["/Users/mahdi/Documents/work/programming/barnameNegar/arbaeenWebApp/node_modules/redux-persist/es/persistCombineReducers.js"],"sourcesContent":["import { combineReducers } from 'redux';\nimport persistReducer from './persistReducer';\nimport autoMergeLevel2 from './stateReconciler/autoMergeLevel2';\n// combineReducers + persistReducer with stateReconciler defaulted to autoMergeLevel2\nexport default function persistCombineReducers(config, reducers) {\n config.stateReconciler = config.stateReconciler === undefined ? autoMergeLevel2 : config.stateReconciler;\n return persistReducer(config, combineReducers(reducers));\n}"],"mappings":"AAAA,SAASA,eAAT,QAAgC,OAAhC;AACA,OAAOC,cAAP,MAA2B,kBAA3B;AACA,OAAOC,eAAP,MAA4B,mCAA5B,C,CACA;;AACA,eAAe,SAASC,sBAAT,CAAgCC,MAAhC,EAAwCC,QAAxC,EAAkD;EAC/DD,MAAM,CAACE,eAAP,GAAyBF,MAAM,CAACE,eAAP,KAA2BC,SAA3B,GAAuCL,eAAvC,GAAyDE,MAAM,CAACE,eAAzF;EACA,OAAOL,cAAc,CAACG,MAAD,EAASJ,eAAe,CAACK,QAAD,CAAxB,CAArB;AACD"},"metadata":{},"sourceType":"module"} |
||||
@ -0,0 +1 @@ |
||||
{"ast":null,"code":"export var KEY_PREFIX = 'persist:';\nexport var FLUSH = 'persist/FLUSH';\nexport var REHYDRATE = 'persist/REHYDRATE';\nexport var PAUSE = 'persist/PAUSE';\nexport var PERSIST = 'persist/PERSIST';\nexport var PURGE = 'persist/PURGE';\nexport var REGISTER = 'persist/REGISTER';\nexport var DEFAULT_VERSION = -1;","map":{"version":3,"names":["KEY_PREFIX","FLUSH","REHYDRATE","PAUSE","PERSIST","PURGE","REGISTER","DEFAULT_VERSION"],"sources":["/Users/mahdi/Documents/work/programming/barnameNegar/arbaeenWebApp/node_modules/redux-persist/es/constants.js"],"sourcesContent":["export var KEY_PREFIX = 'persist:';\nexport var FLUSH = 'persist/FLUSH';\nexport var REHYDRATE = 'persist/REHYDRATE';\nexport var PAUSE = 'persist/PAUSE';\nexport var PERSIST = 'persist/PERSIST';\nexport var PURGE = 'persist/PURGE';\nexport var REGISTER = 'persist/REGISTER';\nexport var DEFAULT_VERSION = -1;"],"mappings":"AAAA,OAAO,IAAIA,UAAU,GAAG,UAAjB;AACP,OAAO,IAAIC,KAAK,GAAG,eAAZ;AACP,OAAO,IAAIC,SAAS,GAAG,mBAAhB;AACP,OAAO,IAAIC,KAAK,GAAG,eAAZ;AACP,OAAO,IAAIC,OAAO,GAAG,iBAAd;AACP,OAAO,IAAIC,KAAK,GAAG,eAAZ;AACP,OAAO,IAAIC,QAAQ,GAAG,kBAAf;AACP,OAAO,IAAIC,eAAe,GAAG,CAAC,CAAvB"},"metadata":{},"sourceType":"module"} |
||||
File diff suppressed because one or more lines are too long
@ -0,0 +1 @@ |
||||
{"ast":null,"code":"\"use strict\";\n\nexports.__esModule = true;\nexports.default = createWebStorage;\n\nvar _getStorage = _interopRequireDefault(require(\"./getStorage\"));\n\nfunction _interopRequireDefault(obj) {\n return obj && obj.__esModule ? obj : {\n default: obj\n };\n}\n\nfunction createWebStorage(type) {\n var storage = (0, _getStorage.default)(type);\n return {\n getItem: function getItem(key) {\n return new Promise(function (resolve, reject) {\n resolve(storage.getItem(key));\n });\n },\n setItem: function setItem(key, item) {\n return new Promise(function (resolve, reject) {\n resolve(storage.setItem(key, item));\n });\n },\n removeItem: function removeItem(key) {\n return new Promise(function (resolve, reject) {\n resolve(storage.removeItem(key));\n });\n }\n };\n}","map":{"version":3,"names":["exports","__esModule","default","createWebStorage","_getStorage","_interopRequireDefault","require","obj","type","storage","getItem","key","Promise","resolve","reject","setItem","item","removeItem"],"sources":["/Users/mahdi/Documents/work/programming/barnameNegar/arbaeenWebApp/node_modules/redux-persist/lib/storage/createWebStorage.js"],"sourcesContent":["\"use strict\";\n\nexports.__esModule = true;\nexports.default = createWebStorage;\n\nvar _getStorage = _interopRequireDefault(require(\"./getStorage\"));\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nfunction createWebStorage(type) {\n var storage = (0, _getStorage.default)(type);\n return {\n getItem: function getItem(key) {\n return new Promise(function (resolve, reject) {\n resolve(storage.getItem(key));\n });\n },\n setItem: function setItem(key, item) {\n return new Promise(function (resolve, reject) {\n resolve(storage.setItem(key, item));\n });\n },\n removeItem: function removeItem(key) {\n return new Promise(function (resolve, reject) {\n resolve(storage.removeItem(key));\n });\n }\n };\n}"],"mappings":"AAAA;;AAEAA,OAAO,CAACC,UAAR,GAAqB,IAArB;AACAD,OAAO,CAACE,OAAR,GAAkBC,gBAAlB;;AAEA,IAAIC,WAAW,GAAGC,sBAAsB,CAACC,OAAO,CAAC,cAAD,CAAR,CAAxC;;AAEA,SAASD,sBAAT,CAAgCE,GAAhC,EAAqC;EAAE,OAAOA,GAAG,IAAIA,GAAG,CAACN,UAAX,GAAwBM,GAAxB,GAA8B;IAAEL,OAAO,EAAEK;EAAX,CAArC;AAAwD;;AAE/F,SAASJ,gBAAT,CAA0BK,IAA1B,EAAgC;EAC9B,IAAIC,OAAO,GAAG,CAAC,GAAGL,WAAW,CAACF,OAAhB,EAAyBM,IAAzB,CAAd;EACA,OAAO;IACLE,OAAO,EAAE,SAASA,OAAT,CAAiBC,GAAjB,EAAsB;MAC7B,OAAO,IAAIC,OAAJ,CAAY,UAAUC,OAAV,EAAmBC,MAAnB,EAA2B;QAC5CD,OAAO,CAACJ,OAAO,CAACC,OAAR,CAAgBC,GAAhB,CAAD,CAAP;MACD,CAFM,CAAP;IAGD,CALI;IAMLI,OAAO,EAAE,SAASA,OAAT,CAAiBJ,GAAjB,EAAsBK,IAAtB,EAA4B;MACnC,OAAO,IAAIJ,OAAJ,CAAY,UAAUC,OAAV,EAAmBC,MAAnB,EAA2B;QAC5CD,OAAO,CAACJ,OAAO,CAACM,OAAR,CAAgBJ,GAAhB,EAAqBK,IAArB,CAAD,CAAP;MACD,CAFM,CAAP;IAGD,CAVI;IAWLC,UAAU,EAAE,SAASA,UAAT,CAAoBN,GAApB,EAAyB;MACnC,OAAO,IAAIC,OAAJ,CAAY,UAAUC,OAAV,EAAmBC,MAAnB,EAA2B;QAC5CD,OAAO,CAACJ,OAAO,CAACQ,UAAR,CAAmBN,GAAnB,CAAD,CAAP;MACD,CAFM,CAAP;IAGD;EAfI,CAAP;AAiBD"},"metadata":{},"sourceType":"script"} |
||||
File diff suppressed because one or more lines are too long
@ -0,0 +1 @@ |
||||
{"ast":null,"code":"export { default as components } from \"./components\";\nexport { default as alert } from \"./alert\";","map":{"version":3,"names":["default","components","alert"],"sources":["/Users/mahdi/Documents/work/programming/barnameNegar/arbaeenWebApp/src/redux/reducers/index.js"],"sourcesContent":["export { default as components } from \"./components\";\nexport { default as alert } from \"./alert\";\n"],"mappings":"AAAA,SAASA,OAAO,IAAIC,UAApB,QAAsC,cAAtC;AACA,SAASD,OAAO,IAAIE,KAApB,QAAiC,SAAjC"},"metadata":{},"sourceType":"module"} |
||||
File diff suppressed because one or more lines are too long
@ -0,0 +1 @@ |
||||
{"ast":null,"code":"export default function createTransform( // @NOTE inbound: transform state coming from redux on its way to being serialized and stored\ninbound, // @NOTE outbound: transform state coming from storage, on its way to be rehydrated into redux\noutbound) {\n var config = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};\n var whitelist = config.whitelist || null;\n var blacklist = config.blacklist || null;\n\n function whitelistBlacklistCheck(key) {\n if (whitelist && whitelist.indexOf(key) === -1) return true;\n if (blacklist && blacklist.indexOf(key) !== -1) return true;\n return false;\n }\n\n return {\n in: function _in(state, key, fullState) {\n return !whitelistBlacklistCheck(key) && inbound ? inbound(state, key, fullState) : state;\n },\n out: function out(state, key, fullState) {\n return !whitelistBlacklistCheck(key) && outbound ? outbound(state, key, fullState) : state;\n }\n };\n}","map":{"version":3,"names":["createTransform","inbound","outbound","config","arguments","length","undefined","whitelist","blacklist","whitelistBlacklistCheck","key","indexOf","in","_in","state","fullState","out"],"sources":["/Users/mahdi/Documents/work/programming/barnameNegar/arbaeenWebApp/node_modules/redux-persist/es/createTransform.js"],"sourcesContent":["export default function createTransform( // @NOTE inbound: transform state coming from redux on its way to being serialized and stored\ninbound, // @NOTE outbound: transform state coming from storage, on its way to be rehydrated into redux\noutbound) {\n var config = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};\n var whitelist = config.whitelist || null;\n var blacklist = config.blacklist || null;\n\n function whitelistBlacklistCheck(key) {\n if (whitelist && whitelist.indexOf(key) === -1) return true;\n if (blacklist && blacklist.indexOf(key) !== -1) return true;\n return false;\n }\n\n return {\n in: function _in(state, key, fullState) {\n return !whitelistBlacklistCheck(key) && inbound ? inbound(state, key, fullState) : state;\n },\n out: function out(state, key, fullState) {\n return !whitelistBlacklistCheck(key) && outbound ? outbound(state, key, fullState) : state;\n }\n };\n}"],"mappings":"AAAA,eAAe,SAASA,eAAT,EAA0B;AACzCC,OADe,EACN;AACTC,QAFe,EAEL;EACR,IAAIC,MAAM,GAAGC,SAAS,CAACC,MAAV,GAAmB,CAAnB,IAAwBD,SAAS,CAAC,CAAD,CAAT,KAAiBE,SAAzC,GAAqDF,SAAS,CAAC,CAAD,CAA9D,GAAoE,EAAjF;EACA,IAAIG,SAAS,GAAGJ,MAAM,CAACI,SAAP,IAAoB,IAApC;EACA,IAAIC,SAAS,GAAGL,MAAM,CAACK,SAAP,IAAoB,IAApC;;EAEA,SAASC,uBAAT,CAAiCC,GAAjC,EAAsC;IACpC,IAAIH,SAAS,IAAIA,SAAS,CAACI,OAAV,CAAkBD,GAAlB,MAA2B,CAAC,CAA7C,EAAgD,OAAO,IAAP;IAChD,IAAIF,SAAS,IAAIA,SAAS,CAACG,OAAV,CAAkBD,GAAlB,MAA2B,CAAC,CAA7C,EAAgD,OAAO,IAAP;IAChD,OAAO,KAAP;EACD;;EAED,OAAO;IACLE,EAAE,EAAE,SAASC,GAAT,CAAaC,KAAb,EAAoBJ,GAApB,EAAyBK,SAAzB,EAAoC;MACtC,OAAO,CAACN,uBAAuB,CAACC,GAAD,CAAxB,IAAiCT,OAAjC,GAA2CA,OAAO,CAACa,KAAD,EAAQJ,GAAR,EAAaK,SAAb,CAAlD,GAA4ED,KAAnF;IACD,CAHI;IAILE,GAAG,EAAE,SAASA,GAAT,CAAaF,KAAb,EAAoBJ,GAApB,EAAyBK,SAAzB,EAAoC;MACvC,OAAO,CAACN,uBAAuB,CAACC,GAAD,CAAxB,IAAiCR,QAAjC,GAA4CA,QAAQ,CAACY,KAAD,EAAQJ,GAAR,EAAaK,SAAb,CAApD,GAA8ED,KAArF;IACD;EANI,CAAP;AAQD"},"metadata":{},"sourceType":"module"} |
||||
@ -0,0 +1 @@ |
||||
{"ast":null,"code":"'use strict';\n\nvar compose = require('redux').compose;\n\nexports.__esModule = true;\nexports.composeWithDevTools = typeof window !== 'undefined' && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ : function () {\n if (arguments.length === 0) return undefined;\n if (typeof arguments[0] === 'object') return compose;\n return compose.apply(null, arguments);\n};\nexports.devToolsEnhancer = typeof window !== 'undefined' && window.__REDUX_DEVTOOLS_EXTENSION__ ? window.__REDUX_DEVTOOLS_EXTENSION__ : function () {\n return function (noop) {\n return noop;\n };\n};","map":{"version":3,"names":["compose","require","exports","__esModule","composeWithDevTools","window","__REDUX_DEVTOOLS_EXTENSION_COMPOSE__","arguments","length","undefined","apply","devToolsEnhancer","__REDUX_DEVTOOLS_EXTENSION__","noop"],"sources":["/Users/mahdi/Documents/work/programming/barnameNegar/arbaeenWebApp/node_modules/redux-devtools-extension/index.js"],"sourcesContent":["'use strict';\n\nvar compose = require('redux').compose;\n\nexports.__esModule = true;\nexports.composeWithDevTools =\n typeof window !== 'undefined' && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__\n ? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__\n : function () {\n if (arguments.length === 0) return undefined;\n if (typeof arguments[0] === 'object') return compose;\n return compose.apply(null, arguments);\n };\n\nexports.devToolsEnhancer =\n typeof window !== 'undefined' && window.__REDUX_DEVTOOLS_EXTENSION__\n ? window.__REDUX_DEVTOOLS_EXTENSION__\n : function () {\n return function (noop) {\n return noop;\n };\n };\n"],"mappings":"AAAA;;AAEA,IAAIA,OAAO,GAAGC,OAAO,CAAC,OAAD,CAAP,CAAiBD,OAA/B;;AAEAE,OAAO,CAACC,UAAR,GAAqB,IAArB;AACAD,OAAO,CAACE,mBAAR,GACE,OAAOC,MAAP,KAAkB,WAAlB,IAAiCA,MAAM,CAACC,oCAAxC,GACID,MAAM,CAACC,oCADX,GAEI,YAAY;EACV,IAAIC,SAAS,CAACC,MAAV,KAAqB,CAAzB,EAA4B,OAAOC,SAAP;EAC5B,IAAI,OAAOF,SAAS,CAAC,CAAD,CAAhB,KAAwB,QAA5B,EAAsC,OAAOP,OAAP;EACtC,OAAOA,OAAO,CAACU,KAAR,CAAc,IAAd,EAAoBH,SAApB,CAAP;AACD,CAPP;AASAL,OAAO,CAACS,gBAAR,GACE,OAAON,MAAP,KAAkB,WAAlB,IAAiCA,MAAM,CAACO,4BAAxC,GACIP,MAAM,CAACO,4BADX,GAEI,YAAY;EACV,OAAO,UAAUC,IAAV,EAAgB;IACrB,OAAOA,IAAP;EACD,CAFD;AAGD,CAPP"},"metadata":{},"sourceType":"script"} |
||||
File diff suppressed because one or more lines are too long
@ -0,0 +1 @@ |
||||
{"ast":null,"code":"\"use strict\";\n\nexports.__esModule = true;\nexports.default = void 0;\n\nvar _createWebStorage = _interopRequireDefault(require(\"./createWebStorage\"));\n\nfunction _interopRequireDefault(obj) {\n return obj && obj.__esModule ? obj : {\n default: obj\n };\n}\n\nvar _default = (0, _createWebStorage.default)('local');\n\nexports.default = _default;","map":{"version":3,"names":["exports","__esModule","default","_createWebStorage","_interopRequireDefault","require","obj","_default"],"sources":["/Users/mahdi/Documents/work/programming/barnameNegar/arbaeenWebApp/node_modules/redux-persist/lib/storage/index.js"],"sourcesContent":["\"use strict\";\n\nexports.__esModule = true;\nexports.default = void 0;\n\nvar _createWebStorage = _interopRequireDefault(require(\"./createWebStorage\"));\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nvar _default = (0, _createWebStorage.default)('local');\n\nexports.default = _default;"],"mappings":"AAAA;;AAEAA,OAAO,CAACC,UAAR,GAAqB,IAArB;AACAD,OAAO,CAACE,OAAR,GAAkB,KAAK,CAAvB;;AAEA,IAAIC,iBAAiB,GAAGC,sBAAsB,CAACC,OAAO,CAAC,oBAAD,CAAR,CAA9C;;AAEA,SAASD,sBAAT,CAAgCE,GAAhC,EAAqC;EAAE,OAAOA,GAAG,IAAIA,GAAG,CAACL,UAAX,GAAwBK,GAAxB,GAA8B;IAAEJ,OAAO,EAAEI;EAAX,CAArC;AAAwD;;AAE/F,IAAIC,QAAQ,GAAG,CAAC,GAAGJ,iBAAiB,CAACD,OAAtB,EAA+B,OAA/B,CAAf;;AAEAF,OAAO,CAACE,OAAR,GAAkBK,QAAlB"},"metadata":{},"sourceType":"script"} |
||||
@ -0,0 +1 @@ |
||||
{"ast":null,"code":"import { KEY_PREFIX } from './constants';\nexport default function getStoredState(config) {\n var transforms = config.transforms || [];\n var storageKey = \"\".concat(config.keyPrefix !== undefined ? config.keyPrefix : KEY_PREFIX).concat(config.key);\n var storage = config.storage;\n var debug = config.debug;\n var deserialize;\n\n if (config.deserialize === false) {\n deserialize = function deserialize(x) {\n return x;\n };\n } else if (typeof config.deserialize === 'function') {\n deserialize = config.deserialize;\n } else {\n deserialize = defaultDeserialize;\n }\n\n return storage.getItem(storageKey).then(function (serialized) {\n if (!serialized) return undefined;else {\n try {\n var state = {};\n var rawState = deserialize(serialized);\n Object.keys(rawState).forEach(function (key) {\n state[key] = transforms.reduceRight(function (subState, transformer) {\n return transformer.out(subState, key, rawState);\n }, deserialize(rawState[key]));\n });\n return state;\n } catch (err) {\n if (process.env.NODE_ENV !== 'production' && debug) console.log(\"redux-persist/getStoredState: Error restoring data \".concat(serialized), err);\n throw err;\n }\n }\n });\n}\n\nfunction defaultDeserialize(serial) {\n return JSON.parse(serial);\n}","map":{"version":3,"names":["KEY_PREFIX","getStoredState","config","transforms","storageKey","concat","keyPrefix","undefined","key","storage","debug","deserialize","x","defaultDeserialize","getItem","then","serialized","state","rawState","Object","keys","forEach","reduceRight","subState","transformer","out","err","process","env","NODE_ENV","console","log","serial","JSON","parse"],"sources":["/Users/mahdi/Documents/work/programming/barnameNegar/arbaeenWebApp/node_modules/redux-persist/es/getStoredState.js"],"sourcesContent":["import { KEY_PREFIX } from './constants';\nexport default function getStoredState(config) {\n var transforms = config.transforms || [];\n var storageKey = \"\".concat(config.keyPrefix !== undefined ? config.keyPrefix : KEY_PREFIX).concat(config.key);\n var storage = config.storage;\n var debug = config.debug;\n var deserialize;\n\n if (config.deserialize === false) {\n deserialize = function deserialize(x) {\n return x;\n };\n } else if (typeof config.deserialize === 'function') {\n deserialize = config.deserialize;\n } else {\n deserialize = defaultDeserialize;\n }\n\n return storage.getItem(storageKey).then(function (serialized) {\n if (!serialized) return undefined;else {\n try {\n var state = {};\n var rawState = deserialize(serialized);\n Object.keys(rawState).forEach(function (key) {\n state[key] = transforms.reduceRight(function (subState, transformer) {\n return transformer.out(subState, key, rawState);\n }, deserialize(rawState[key]));\n });\n return state;\n } catch (err) {\n if (process.env.NODE_ENV !== 'production' && debug) console.log(\"redux-persist/getStoredState: Error restoring data \".concat(serialized), err);\n throw err;\n }\n }\n });\n}\n\nfunction defaultDeserialize(serial) {\n return JSON.parse(serial);\n}"],"mappings":"AAAA,SAASA,UAAT,QAA2B,aAA3B;AACA,eAAe,SAASC,cAAT,CAAwBC,MAAxB,EAAgC;EAC7C,IAAIC,UAAU,GAAGD,MAAM,CAACC,UAAP,IAAqB,EAAtC;EACA,IAAIC,UAAU,GAAG,GAAGC,MAAH,CAAUH,MAAM,CAACI,SAAP,KAAqBC,SAArB,GAAiCL,MAAM,CAACI,SAAxC,GAAoDN,UAA9D,EAA0EK,MAA1E,CAAiFH,MAAM,CAACM,GAAxF,CAAjB;EACA,IAAIC,OAAO,GAAGP,MAAM,CAACO,OAArB;EACA,IAAIC,KAAK,GAAGR,MAAM,CAACQ,KAAnB;EACA,IAAIC,WAAJ;;EAEA,IAAIT,MAAM,CAACS,WAAP,KAAuB,KAA3B,EAAkC;IAChCA,WAAW,GAAG,SAASA,WAAT,CAAqBC,CAArB,EAAwB;MACpC,OAAOA,CAAP;IACD,CAFD;EAGD,CAJD,MAIO,IAAI,OAAOV,MAAM,CAACS,WAAd,KAA8B,UAAlC,EAA8C;IACnDA,WAAW,GAAGT,MAAM,CAACS,WAArB;EACD,CAFM,MAEA;IACLA,WAAW,GAAGE,kBAAd;EACD;;EAED,OAAOJ,OAAO,CAACK,OAAR,CAAgBV,UAAhB,EAA4BW,IAA5B,CAAiC,UAAUC,UAAV,EAAsB;IAC5D,IAAI,CAACA,UAAL,EAAiB,OAAOT,SAAP,CAAjB,KAAuC;MACrC,IAAI;QACF,IAAIU,KAAK,GAAG,EAAZ;QACA,IAAIC,QAAQ,GAAGP,WAAW,CAACK,UAAD,CAA1B;QACAG,MAAM,CAACC,IAAP,CAAYF,QAAZ,EAAsBG,OAAtB,CAA8B,UAAUb,GAAV,EAAe;UAC3CS,KAAK,CAACT,GAAD,CAAL,GAAaL,UAAU,CAACmB,WAAX,CAAuB,UAAUC,QAAV,EAAoBC,WAApB,EAAiC;YACnE,OAAOA,WAAW,CAACC,GAAZ,CAAgBF,QAAhB,EAA0Bf,GAA1B,EAA+BU,QAA/B,CAAP;UACD,CAFY,EAEVP,WAAW,CAACO,QAAQ,CAACV,GAAD,CAAT,CAFD,CAAb;QAGD,CAJD;QAKA,OAAOS,KAAP;MACD,CATD,CASE,OAAOS,GAAP,EAAY;QACZ,IAAIC,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAAzB,IAAyCnB,KAA7C,EAAoDoB,OAAO,CAACC,GAAR,CAAY,sDAAsD1B,MAAtD,CAA6DW,UAA7D,CAAZ,EAAsFU,GAAtF;QACpD,MAAMA,GAAN;MACD;IACF;EACF,CAhBM,CAAP;AAiBD;;AAED,SAASb,kBAAT,CAA4BmB,MAA5B,EAAoC;EAClC,OAAOC,IAAI,CAACC,KAAL,CAAWF,MAAX,CAAP;AACD"},"metadata":{},"sourceType":"module"} |
||||
@ -0,0 +1 @@ |
||||
{"ast":null,"code":"/** A function that accepts a potential \"extra argument\" value to be injected later,\r\n * and returns an instance of the thunk middleware that uses that value\r\n */\nfunction createThunkMiddleware(extraArgument) {\n // Standard Redux middleware definition pattern:\n // See: https://redux.js.org/tutorials/fundamentals/part-4-store#writing-custom-middleware\n var middleware = function middleware(_ref) {\n var dispatch = _ref.dispatch,\n getState = _ref.getState;\n return function (next) {\n return function (action) {\n // The thunk middleware looks for any functions that were passed to `store.dispatch`.\n // If this \"action\" is really a function, call it and return the result.\n if (typeof action === 'function') {\n // Inject the store's `dispatch` and `getState` methods, as well as any \"extra arg\"\n return action(dispatch, getState, extraArgument);\n } // Otherwise, pass the action down the middleware chain as usual\n\n\n return next(action);\n };\n };\n };\n\n return middleware;\n}\n\nvar thunk = createThunkMiddleware(); // Attach the factory function so users can create a customized version\n// with whatever \"extra arg\" they want to inject into their thunks\n\nthunk.withExtraArgument = createThunkMiddleware;\nexport default thunk;","map":{"version":3,"names":["createThunkMiddleware","extraArgument","middleware","_ref","dispatch","getState","next","action","thunk","withExtraArgument"],"sources":["/Users/mahdi/Documents/work/programming/barnameNegar/arbaeenWebApp/node_modules/redux-thunk/es/index.js"],"sourcesContent":["/** A function that accepts a potential \"extra argument\" value to be injected later,\r\n * and returns an instance of the thunk middleware that uses that value\r\n */\nfunction createThunkMiddleware(extraArgument) {\n // Standard Redux middleware definition pattern:\n // See: https://redux.js.org/tutorials/fundamentals/part-4-store#writing-custom-middleware\n var middleware = function middleware(_ref) {\n var dispatch = _ref.dispatch,\n getState = _ref.getState;\n return function (next) {\n return function (action) {\n // The thunk middleware looks for any functions that were passed to `store.dispatch`.\n // If this \"action\" is really a function, call it and return the result.\n if (typeof action === 'function') {\n // Inject the store's `dispatch` and `getState` methods, as well as any \"extra arg\"\n return action(dispatch, getState, extraArgument);\n } // Otherwise, pass the action down the middleware chain as usual\n\n\n return next(action);\n };\n };\n };\n\n return middleware;\n}\n\nvar thunk = createThunkMiddleware(); // Attach the factory function so users can create a customized version\n// with whatever \"extra arg\" they want to inject into their thunks\n\nthunk.withExtraArgument = createThunkMiddleware;\nexport default thunk;"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,qBAAT,CAA+BC,aAA/B,EAA8C;EAC5C;EACA;EACA,IAAIC,UAAU,GAAG,SAASA,UAAT,CAAoBC,IAApB,EAA0B;IACzC,IAAIC,QAAQ,GAAGD,IAAI,CAACC,QAApB;IAAA,IACIC,QAAQ,GAAGF,IAAI,CAACE,QADpB;IAEA,OAAO,UAAUC,IAAV,EAAgB;MACrB,OAAO,UAAUC,MAAV,EAAkB;QACvB;QACA;QACA,IAAI,OAAOA,MAAP,KAAkB,UAAtB,EAAkC;UAChC;UACA,OAAOA,MAAM,CAACH,QAAD,EAAWC,QAAX,EAAqBJ,aAArB,CAAb;QACD,CANsB,CAMrB;;;QAGF,OAAOK,IAAI,CAACC,MAAD,CAAX;MACD,CAVD;IAWD,CAZD;EAaD,CAhBD;;EAkBA,OAAOL,UAAP;AACD;;AAED,IAAIM,KAAK,GAAGR,qBAAqB,EAAjC,C,CAAqC;AACrC;;AAEAQ,KAAK,CAACC,iBAAN,GAA0BT,qBAA1B;AACA,eAAeQ,KAAf"},"metadata":{},"sourceType":"module"} |
||||
@ -0,0 +1 @@ |
||||
{"ast":null,"code":"","map":{"version":3,"names":[],"sources":["/Users/mahdi/Documents/work/programming/barnameNegar/arbaeenWebApp/src/redux/reducers/index.js"],"sourcesContent":[""],"mappings":""},"metadata":{},"sourceType":"module"} |
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,8 @@ |
||||
# Change Log |
||||
|
||||
All notable changes to this project will be documented in this file. |
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. |
||||
|
||||
## 2.13.9 (2021-03-06) |
||||
|
||||
**Note:** Version bump only for package redux-devtools-extension |
||||
@ -0,0 +1,50 @@ |
||||
# Redux DevTools Extension's helper |
||||
|
||||
[](https://gitter.im/zalmoxisus/redux-devtools-extension?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) |
||||
|
||||
## Usage |
||||
|
||||
Install: |
||||
|
||||
``` |
||||
npm install --save redux-devtools-extension |
||||
``` |
||||
|
||||
and use like that: |
||||
|
||||
```js |
||||
import { createStore, applyMiddleware } from 'redux'; |
||||
import { composeWithDevTools } from 'redux-devtools-extension'; |
||||
|
||||
const store = createStore( |
||||
reducer, |
||||
composeWithDevTools( |
||||
applyMiddleware(...middleware) |
||||
// other store enhancers if any |
||||
) |
||||
); |
||||
``` |
||||
|
||||
or if needed to apply [extension’s options](https://github.com/zalmoxisus/redux-devtools-extension/blob/master/docs/API/Arguments.md#windowdevtoolsextensionconfig): |
||||
|
||||
```js |
||||
import { createStore, applyMiddleware } from 'redux'; |
||||
import { composeWithDevTools } from 'redux-devtools-extension'; |
||||
|
||||
const composeEnhancers = composeWithDevTools({ |
||||
// Specify here name, actionsBlacklist, actionsCreators and other options |
||||
}); |
||||
const store = createStore( |
||||
reducer, |
||||
composeEnhancers( |
||||
applyMiddleware(...middleware) |
||||
// other store enhancers if any |
||||
) |
||||
); |
||||
``` |
||||
|
||||
There’re just [few lines of code](https://github.com/zalmoxisus/redux-devtools-extension/blob/master/npm-package/index.js). If you don’t want to allow the extension in production, just use ‘redux-devtools-extension/developmentOnly’ instead of ‘redux-devtools-extension’. |
||||
|
||||
## License |
||||
|
||||
MIT |
||||
@ -0,0 +1 @@ |
||||
export * from 'redux-devtools-extension'; |
||||
@ -0,0 +1,26 @@ |
||||
'use strict'; |
||||
|
||||
var compose = require('redux').compose; |
||||
|
||||
exports.__esModule = true; |
||||
exports.composeWithDevTools = |
||||
process.env.NODE_ENV !== 'production' && |
||||
typeof window !== 'undefined' && |
||||
window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ |
||||
? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ |
||||
: function () { |
||||
if (arguments.length === 0) return undefined; |
||||
if (typeof arguments[0] === 'object') return compose; |
||||
return compose.apply(null, arguments); |
||||
}; |
||||
|
||||
exports.devToolsEnhancer = |
||||
process.env.NODE_ENV !== 'production' && |
||||
typeof window !== 'undefined' && |
||||
window.__REDUX_DEVTOOLS_EXTENSION__ |
||||
? window.__REDUX_DEVTOOLS_EXTENSION__ |
||||
: function () { |
||||
return function (noop) { |
||||
return noop; |
||||
}; |
||||
}; |
||||
@ -0,0 +1,174 @@ |
||||
import { Action, ActionCreator, StoreEnhancer, compose } from 'redux'; |
||||
|
||||
export interface EnhancerOptions { |
||||
/** |
||||
* the instance name to be showed on the monitor page. Default value is `document.title`. |
||||
* If not specified and there's no document title, it will consist of `tabId` and `instanceId`. |
||||
*/ |
||||
name?: string; |
||||
/** |
||||
* action creators functions to be available in the Dispatcher. |
||||
*/ |
||||
actionCreators?: ActionCreator<any>[] | { [key: string]: ActionCreator<any> }; |
||||
/** |
||||
* if more than one action is dispatched in the indicated interval, all new actions will be collected and sent at once. |
||||
* It is the joint between performance and speed. When set to `0`, all actions will be sent instantly. |
||||
* Set it to a higher value when experiencing perf issues (also `maxAge` to a lower value). |
||||
* |
||||
* @default 500 ms. |
||||
*/ |
||||
latency?: number; |
||||
/** |
||||
* (> 1) - maximum allowed actions to be stored in the history tree. The oldest actions are removed once maxAge is reached. It's critical for performance. |
||||
* |
||||
* @default 50 |
||||
*/ |
||||
maxAge?: number; |
||||
/** |
||||
* - `undefined` - will use regular `JSON.stringify` to send data (it's the fast mode). |
||||
* - `false` - will handle also circular references. |
||||
* - `true` - will handle also date, regex, undefined, error objects, symbols, maps, sets and functions. |
||||
* - object, which contains `date`, `regex`, `undefined`, `error`, `symbol`, `map`, `set` and `function` keys. |
||||
* For each of them you can indicate if to include (by setting as `true`). |
||||
* For `function` key you can also specify a custom function which handles serialization. |
||||
* See [`jsan`](https://github.com/kolodny/jsan) for more details.
|
||||
*/ |
||||
serialize?: |
||||
| boolean |
||||
| { |
||||
date?: boolean; |
||||
regex?: boolean; |
||||
undefined?: boolean; |
||||
error?: boolean; |
||||
symbol?: boolean; |
||||
map?: boolean; |
||||
set?: boolean; |
||||
function?: boolean | Function; |
||||
}; |
||||
/** |
||||
* function which takes `action` object and id number as arguments, and should return `action` object back. |
||||
*/ |
||||
actionSanitizer?: <A extends Action>(action: A, id: number) => A; |
||||
/** |
||||
* function which takes `state` object and index as arguments, and should return `state` object back. |
||||
*/ |
||||
stateSanitizer?: <S>(state: S, index: number) => S; |
||||
/** |
||||
* *string or array of strings as regex* - actions types to be hidden / shown in the monitors (while passed to the reducers). |
||||
* If `actionsWhitelist` specified, `actionsBlacklist` is ignored. |
||||
*/ |
||||
actionsBlacklist?: string | string[]; |
||||
/** |
||||
* *string or array of strings as regex* - actions types to be hidden / shown in the monitors (while passed to the reducers). |
||||
* If `actionsWhitelist` specified, `actionsBlacklist` is ignored. |
||||
*/ |
||||
actionsWhitelist?: string | string[]; |
||||
/** |
||||
* called for every action before sending, takes `state` and `action` object, and returns `true` in case it allows sending the current data to the monitor. |
||||
* Use it as a more advanced version of `actionsBlacklist`/`actionsWhitelist` parameters. |
||||
*/ |
||||
predicate?: <S, A extends Action>(state: S, action: A) => boolean; |
||||
/** |
||||
* if specified as `false`, it will not record the changes till clicking on `Start recording` button. |
||||
* Available only for Redux enhancer, for others use `autoPause`. |
||||
* |
||||
* @default true |
||||
*/ |
||||
shouldRecordChanges?: boolean; |
||||
/** |
||||
* if specified, whenever clicking on `Pause recording` button and there are actions in the history log, will add this action type. |
||||
* If not specified, will commit when paused. Available only for Redux enhancer. |
||||
* |
||||
* @default "@@PAUSED"" |
||||
*/ |
||||
pauseActionType?: string; |
||||
/** |
||||
* auto pauses when the extension’s window is not opened, and so has zero impact on your app when not in use. |
||||
* Not available for Redux enhancer (as it already does it but storing the data to be sent). |
||||
* |
||||
* @default false |
||||
*/ |
||||
autoPause?: boolean; |
||||
/** |
||||
* if specified as `true`, it will not allow any non-monitor actions to be dispatched till clicking on `Unlock changes` button. |
||||
* Available only for Redux enhancer. |
||||
* |
||||
* @default false |
||||
*/ |
||||
shouldStartLocked?: boolean; |
||||
/** |
||||
* if set to `false`, will not recompute the states on hot reloading (or on replacing the reducers). Available only for Redux enhancer. |
||||
* |
||||
* @default true |
||||
*/ |
||||
shouldHotReload?: boolean; |
||||
/** |
||||
* if specified as `true`, whenever there's an exception in reducers, the monitors will show the error message, and next actions will not be dispatched. |
||||
* |
||||
* @default false |
||||
*/ |
||||
shouldCatchErrors?: boolean; |
||||
/** |
||||
* If you want to restrict the extension, specify the features you allow. |
||||
* If not specified, all of the features are enabled. When set as an object, only those included as `true` will be allowed. |
||||
* Note that except `true`/`false`, `import` and `export` can be set as `custom` (which is by default for Redux enhancer), meaning that the importing/exporting occurs on the client side. |
||||
* Otherwise, you'll get/set the data right from the monitor part. |
||||
*/ |
||||
features?: { |
||||
/** |
||||
* start/pause recording of dispatched actions |
||||
*/ |
||||
pause?: boolean; |
||||
/** |
||||
* lock/unlock dispatching actions and side effects |
||||
*/ |
||||
lock?: boolean; |
||||
/** |
||||
* persist states on page reloading |
||||
*/ |
||||
persist?: boolean; |
||||
/** |
||||
* export history of actions in a file |
||||
*/ |
||||
export?: boolean | 'custom'; |
||||
/** |
||||
* import history of actions from a file |
||||
*/ |
||||
import?: boolean | 'custom'; |
||||
/** |
||||
* jump back and forth (time travelling) |
||||
*/ |
||||
jump?: boolean; |
||||
/** |
||||
* skip (cancel) actions |
||||
*/ |
||||
skip?: boolean; |
||||
/** |
||||
* drag and drop actions in the history list |
||||
*/ |
||||
reorder?: boolean; |
||||
/** |
||||
* dispatch custom actions or action creators |
||||
*/ |
||||
dispatch?: boolean; |
||||
/** |
||||
* generate tests for the selected actions |
||||
*/ |
||||
test?: boolean; |
||||
}; |
||||
/** |
||||
* Set to true or a stacktrace-returning function to record call stack traces for dispatched actions. |
||||
* Defaults to false. |
||||
*/ |
||||
trace?: boolean | (<A extends Action>(action: A) => string); |
||||
/** |
||||
* The maximum number of stack trace entries to record per action. Defaults to 10. |
||||
*/ |
||||
traceLimit?: number; |
||||
} |
||||
|
||||
export function composeWithDevTools<StoreExt, StateExt>( |
||||
...funcs: Array<StoreEnhancer<StoreExt>> |
||||
): StoreEnhancer<StoreExt>; |
||||
export function composeWithDevTools(options: EnhancerOptions): typeof compose; |
||||
export function devToolsEnhancer(options: EnhancerOptions): StoreEnhancer<any>; |
||||
@ -0,0 +1,22 @@ |
||||
'use strict'; |
||||
|
||||
var compose = require('redux').compose; |
||||
|
||||
exports.__esModule = true; |
||||
exports.composeWithDevTools = |
||||
typeof window !== 'undefined' && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ |
||||
? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ |
||||
: function () { |
||||
if (arguments.length === 0) return undefined; |
||||
if (typeof arguments[0] === 'object') return compose; |
||||
return compose.apply(null, arguments); |
||||
}; |
||||
|
||||
exports.devToolsEnhancer = |
||||
typeof window !== 'undefined' && window.__REDUX_DEVTOOLS_EXTENSION__ |
||||
? window.__REDUX_DEVTOOLS_EXTENSION__ |
||||
: function () { |
||||
return function (noop) { |
||||
return noop; |
||||
}; |
||||
}; |
||||
@ -0,0 +1 @@ |
||||
export * from 'redux-devtools-extension'; |
||||
@ -0,0 +1,60 @@ |
||||
'use strict'; |
||||
|
||||
var assign = require('./utils/assign'); |
||||
var compose = require('redux').compose; |
||||
|
||||
function enhancer() { |
||||
var config = arguments[0] || {}; |
||||
config.features = { pause: true, export: true, test: true }; |
||||
config.type = 'redux'; |
||||
if (config.autoPause === undefined) config.autoPause = true; |
||||
if (config.latency === undefined) config.latency = 500; |
||||
|
||||
return function (createStore) { |
||||
return function (reducer, preloadedState, enhancer) { |
||||
var store = createStore(reducer, preloadedState, enhancer); |
||||
var origDispatch = store.dispatch; |
||||
|
||||
var devTools = window.__REDUX_DEVTOOLS_EXTENSION__.connect(config); |
||||
devTools.init(store.getState()); |
||||
|
||||
var dispatch = function (action) { |
||||
var r = origDispatch(action); |
||||
devTools.send(action, store.getState()); |
||||
return r; |
||||
}; |
||||
|
||||
if (Object.assign) return Object.assign(store, { dispatch: dispatch }); |
||||
return assign(store, 'dispatch', dispatch); |
||||
}; |
||||
}; |
||||
} |
||||
|
||||
function composeWithEnhancer(config) { |
||||
return function () { |
||||
return compose(compose.apply(null, arguments), enhancer(config)); |
||||
}; |
||||
} |
||||
|
||||
exports.__esModule = true; |
||||
exports.composeWithDevTools = function () { |
||||
if (typeof window !== 'undefined' && window.__REDUX_DEVTOOLS_EXTENSION__) { |
||||
if (arguments.length === 0) return enhancer(); |
||||
if (typeof arguments[0] === 'object') |
||||
return composeWithEnhancer(arguments[0]); |
||||
return composeWithEnhancer().apply(null, arguments); |
||||
} |
||||
|
||||
if (arguments.length === 0) return undefined; |
||||
if (typeof arguments[0] === 'object') return compose; |
||||
return compose.apply(null, arguments); |
||||
}; |
||||
|
||||
exports.devToolsEnhancer = |
||||
typeof window !== 'undefined' && window.__REDUX_DEVTOOLS_EXTENSION__ |
||||
? enhancer |
||||
: function () { |
||||
return function (noop) { |
||||
return noop; |
||||
}; |
||||
}; |
||||
@ -0,0 +1 @@ |
||||
export * from 'redux-devtools-extension'; |
||||
@ -0,0 +1,28 @@ |
||||
'use strict'; |
||||
|
||||
var compose = require('redux').compose; |
||||
var logOnly = require('./logOnly'); |
||||
|
||||
exports.__esModule = true; |
||||
exports.composeWithDevTools = |
||||
process.env.NODE_ENV === 'production' |
||||
? logOnly.composeWithDevTools |
||||
: typeof window !== 'undefined' && |
||||
window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ |
||||
? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ |
||||
: function () { |
||||
if (arguments.length === 0) return undefined; |
||||
if (typeof arguments[0] === 'object') return compose; |
||||
return compose.apply(null, arguments); |
||||
}; |
||||
|
||||
exports.devToolsEnhancer = |
||||
process.env.NODE_ENV === 'production' |
||||
? logOnly.devToolsEnhancer |
||||
: typeof window !== 'undefined' && window.__REDUX_DEVTOOLS_EXTENSION__ |
||||
? window.__REDUX_DEVTOOLS_EXTENSION__ |
||||
: function () { |
||||
return function (noop) { |
||||
return noop; |
||||
}; |
||||
}; |
||||
@ -0,0 +1,17 @@ |
||||
{ |
||||
"name": "redux-devtools-extension", |
||||
"version": "2.13.9", |
||||
"description": "Wrappers for Redux DevTools Extension.", |
||||
"main": "index.js", |
||||
"repository": { |
||||
"type": "git", |
||||
"url": "https://github.com/zalmoxisus/redux-devtools-extension" |
||||
}, |
||||
"homepage": "https://github.com/zalmoxisus/redux-devtools-extension", |
||||
"author": "Mihail Diordiev <zalmoxisus@gmail.com> (https://github.com/zalmoxisus)", |
||||
"license": "MIT", |
||||
"peerDependencies": { |
||||
"redux": "^3.1.0 || ^4.0.0" |
||||
}, |
||||
"gitHead": "5ef9b00cd4717ac878068ce8003e1999e680c72e" |
||||
} |
||||
@ -0,0 +1,24 @@ |
||||
var objectKeys = |
||||
Object.keys || |
||||
function (obj) { |
||||
var keys = []; |
||||
for (var key in obj) { |
||||
if ({}.hasOwnProperty.call(obj, key)) keys.push(key); |
||||
} |
||||
return keys; |
||||
}; |
||||
|
||||
function assign(obj, newKey, newValue) { |
||||
var keys = objectKeys(obj); |
||||
var copy = {}; |
||||
|
||||
for (var i = 0, l = keys.length; i < l; i++) { |
||||
var key = keys[i]; |
||||
copy[key] = obj[key]; |
||||
} |
||||
|
||||
copy[newKey] = newValue; |
||||
return copy; |
||||
} |
||||
|
||||
module.exports = assign; |
||||
@ -0,0 +1,20 @@ |
||||
# Changelog |
||||
All notable changes to this project will be documented in this file. |
||||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), |
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). |
||||
|
||||
## [Unreleased] |
||||
### Added |
||||
- [PR #974](https://github.com/rt2zz/redux-persist/pull/974) **Add correct PersistGate defaultProps to support newer flow versions.** Adds `children` to defaultProps in `PersistGate` component and removes the optional (`?`) flag in order to be compatible with flow type checking (more explanation can be found in [this flow issue](facebook/flow#1660)). Fixes [#953](https://github.com/rt2zz/redux-persist/issues/953) |
||||
- [PR #949](https://github.com/rt2zz/redux-persist/pull/949) **Allow onWriteFail |
||||
to be passed in config.** The value should be a function to be called in the |
||||
case a write fails (i.e. because the disk it out of space). |
||||
- **Add Community section to README.** Add link to Reactiflux #redux-persist |
||||
channel. Add blog articles about redux-persist from the community. |
||||
|
||||
## 0.2.0 through 5.10.0 - 2015-07-24 through 2018-06-05 |
||||
See notes on [GitHub releases page](https://github.com/rt2zz/redux-persist/releases) |
||||
|
||||
[Unreleased]: https://github.com/olivierlacan/keep-a-changelog/compare/v5.10.0...HEAD |
||||
[0.2.0 through 5.10.0]: See notes on [GitHub releases page](https://github.com/rt2zz/redux-persist/releases) |
||||
@ -0,0 +1,21 @@ |
||||
MIT License |
||||
|
||||
Copyright (c) 2017 Zack Story |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
of this software and associated documentation files (the "Software"), to deal |
||||
in the Software without restriction, including without limitation the rights |
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
copies of the Software, and to permit persons to whom the Software is |
||||
furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included in all |
||||
copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
||||
SOFTWARE. |
||||
@ -0,0 +1,266 @@ |
||||
# Redux Persist |
||||
|
||||
Persist and rehydrate a redux store. |
||||
|
||||
[](https://travis-ci.org/rt2zz/redux-persist) [](https://www.npmjs.com/package/redux-persist) [](https://www.npmjs.com/package/redux-persist) |
||||
[](https://discord.gg/ExrEvmv) |
||||
|
||||
## Quickstart |
||||
`npm install redux-persist` |
||||
|
||||
Usage Examples: |
||||
1. [Basic Usage](#basic-usage) |
||||
2. [Nested Persists](#nested-persists) |
||||
3. [Hot Module Replacement](./docs/hot-module-replacement.md) |
||||
4. Code Splitting [coming soon] |
||||
|
||||
#### Basic Usage |
||||
Basic usage involves adding `persistReducer` and `persistStore` to your setup. **IMPORTANT** Every app needs to decide how many levels of state they want to "merge". The default is 1 level. Please read through the [state reconciler docs](#state-reconciler) for more information. |
||||
|
||||
```js |
||||
// configureStore.js |
||||
|
||||
import { createStore } from 'redux' |
||||
import { persistStore, persistReducer } from 'redux-persist' |
||||
import storage from 'redux-persist/lib/storage' // defaults to localStorage for web |
||||
|
||||
import rootReducer from './reducers' |
||||
|
||||
const persistConfig = { |
||||
key: 'root', |
||||
storage, |
||||
} |
||||
|
||||
const persistedReducer = persistReducer(persistConfig, rootReducer) |
||||
|
||||
export default () => { |
||||
let store = createStore(persistedReducer) |
||||
let persistor = persistStore(store) |
||||
return { store, persistor } |
||||
} |
||||
``` |
||||
|
||||
If you are using react, wrap your root component with [PersistGate](./docs/PersistGate.md). This delays the rendering of your app's UI until your persisted state has been retrieved and saved to redux. **NOTE** the `PersistGate` loading prop can be null, or any react instance, e.g. `loading={<Loading />}` |
||||
|
||||
```js |
||||
import { PersistGate } from 'redux-persist/integration/react' |
||||
|
||||
// ... normal setup, create store and persistor, import components etc. |
||||
|
||||
const App = () => { |
||||
return ( |
||||
<Provider store={store}> |
||||
<PersistGate loading={null} persistor={persistor}> |
||||
<RootComponent /> |
||||
</PersistGate> |
||||
</Provider> |
||||
); |
||||
}; |
||||
``` |
||||
|
||||
## API |
||||
[Full API](./docs/api.md) |
||||
|
||||
#### `persistReducer(config, reducer)` |
||||
- arguments |
||||
- [**config**](https://github.com/rt2zz/redux-persist/blob/master/src/types.js#L13-L27) *object* |
||||
- required config: `key, storage` |
||||
- notable other config: `whitelist, blacklist, version, stateReconciler, debug` |
||||
- **reducer** *function* |
||||
- any reducer will work, typically this would be the top level reducer returned by `combineReducers` |
||||
- returns an enhanced reducer |
||||
|
||||
#### `persistStore(store, [config, callback])` |
||||
- arguments |
||||
- **store** *redux store* The store to be persisted. |
||||
- **config** *object* (typically null) |
||||
- If you want to avoid that the persistence starts immediately after calling `persistStore`, set the option manualPersist. Example: `{ manualPersist: true }` Persistence can then be started at any point with `peristor.persist()`. You usually want to do this if your storage is not ready when the `persistStore` call is made. |
||||
- **callback** *function* will be called after rehydration is finished. |
||||
- returns **persistor** object |
||||
|
||||
#### `persistor object` |
||||
- the persistor object is returned by persistStore with the following methods: |
||||
- `.purge()` |
||||
- purges state from disk and returns a promise |
||||
- `.flush()` |
||||
- immediately writes all pending state to disk and returns a promise |
||||
- `.pause()` |
||||
- pauses persistence |
||||
- `.persist()` |
||||
- resumes persistence |
||||
|
||||
## State Reconciler |
||||
State reconcilers define how incoming state is merged in with initial state. It is critical to choose the right state reconciler for your state. There are three options that ship out of the box, let's look at how each operates: |
||||
|
||||
1. **hardSet** (`import hardSet from 'redux-persist/lib/stateReconciler/hardSet'`) |
||||
This will hard set incoming state. This can be desirable in some cases where persistReducer is nested deeper in your reducer tree, or if you do not rely on initialState in your reducer. |
||||
- **incoming state**: `{ foo: incomingFoo }` |
||||
- **initial state**: `{ foo: initialFoo, bar: initialBar }` |
||||
- **reconciled state**: `{ foo: incomingFoo }` // note bar has been dropped |
||||
2. **autoMergeLevel1** (default) |
||||
This will auto merge one level deep. Auto merge means if the some piece of substate was modified by your reducer during the REHYDRATE action, it will skip this piece of state. Level 1 means it will shallow merge 1 level deep. |
||||
- **incoming state**: `{ foo: incomingFoo }` |
||||
- **initial state**: `{ foo: initialFoo, bar: initialBar }` |
||||
- **reconciled state**: `{ foo: incomingFoo, bar: initialBar }` // note incomingFoo overwrites initialFoo |
||||
3. **autoMergeLevel2** (`import autoMergeLevel2 from 'redux-persist/lib/stateReconciler/autoMergeLevel2'`) |
||||
This acts just like autoMergeLevel1, except it shallow merges two levels |
||||
- **incoming state**: `{ foo: incomingFoo }` |
||||
- **initial state**: `{ foo: initialFoo, bar: initialBar }` |
||||
- **reconciled state**: `{ foo: mergedFoo, bar: initialBar }` // note: initialFoo and incomingFoo are shallow merged |
||||
|
||||
#### Example |
||||
```js |
||||
import hardSet from 'redux-persist/lib/stateReconciler/hardSet' |
||||
|
||||
const persistConfig = { |
||||
key: 'root', |
||||
storage, |
||||
stateReconciler: hardSet, |
||||
} |
||||
``` |
||||
|
||||
## React Integration |
||||
Redux persist ships with react integration as a convenience. The `PersistGate` component is the recommended way to delay rendering until persistence is complete. It works in one of two modes: |
||||
1. `loading` prop: The provided loading value will be rendered until persistence is complete at which point children will be rendered. |
||||
2. function children: The function will be invoked with a single `bootstrapped` argument. When bootstrapped is true, persistence is complete and it is safe to render the full app. This can be useful for adding transition animations. |
||||
|
||||
## Blacklist & Whitelist |
||||
By Example: |
||||
```js |
||||
// BLACKLIST |
||||
const persistConfig = { |
||||
key: 'root', |
||||
storage: storage, |
||||
blacklist: ['navigation'] // navigation will not be persisted |
||||
}; |
||||
|
||||
// WHITELIST |
||||
const persistConfig = { |
||||
key: 'root', |
||||
storage: storage, |
||||
whitelist: ['navigation'] // only navigation will be persisted |
||||
}; |
||||
``` |
||||
|
||||
## Nested Persists |
||||
Nested persist can be useful for including different storage adapters, code splitting, or deep filtering. For example while blacklist and whitelist only work one level deep, but we can use a nested persist to blacklist a deeper value: |
||||
```js |
||||
import { combineReducers } from 'redux' |
||||
import { persistReducer } from 'redux-persist' |
||||
import storage from 'redux-persist/lib/storage' |
||||
|
||||
import { authReducer, otherReducer } from './reducers' |
||||
|
||||
const rootPersistConfig = { |
||||
key: 'root', |
||||
storage: storage, |
||||
blacklist: ['auth'] |
||||
} |
||||
|
||||
const authPersistConfig = { |
||||
key: 'auth', |
||||
storage: storage, |
||||
blacklist: ['somethingTemporary'] |
||||
} |
||||
|
||||
const rootReducer = combineReducers({ |
||||
auth: persistReducer(authPersistConfig, authReducer), |
||||
other: otherReducer, |
||||
}) |
||||
|
||||
export default persistReducer(rootPersistConfig, rootReducer) |
||||
``` |
||||
|
||||
## Migrations |
||||
`persistReducer` has a general purpose "migrate" config which will be called after getting stored state but before actually reconciling with the reducer. It can be any function which takes state as an argument and returns a promise to return a new state object. |
||||
|
||||
Redux Persist ships with `createMigrate`, which helps create a synchronous migration for moving from any version of stored state to the current state version. [[Additional information]](./docs/migrations.md) |
||||
|
||||
## Transforms |
||||
Transforms allow you to customize the state object that gets persisted and rehydrated. |
||||
|
||||
There are several libraries that tackle some of the common implementations for transforms. |
||||
- [immutable](https://github.com/rt2zz/redux-persist-transform-immutable) - support immutable reducers |
||||
- [seamless-immutable](https://github.com/hilkeheremans/redux-persist-seamless-immutable) - support seamless-immutable reducers |
||||
- [compress](https://github.com/rt2zz/redux-persist-transform-compress) - compress your serialized state with lz-string |
||||
- [encrypt](https://github.com/maxdeviant/redux-persist-transform-encrypt) - encrypt your serialized state with AES |
||||
- [filter](https://github.com/edy/redux-persist-transform-filter) - store or load a subset of your state |
||||
- [filter-immutable](https://github.com/actra-development/redux-persist-transform-filter-immutable) - store or load a subset of your state with support for immutablejs |
||||
- [expire](https://github.com/gabceb/redux-persist-transform-expire) - expire a specific subset of your state based on a property |
||||
- [expire-reducer](https://github.com/kamranahmedse/redux-persist-expire) - more flexible alternative to expire transformer above with more options |
||||
|
||||
When the state object gets persisted, it first gets serialized with `JSON.stringify()`. If parts of your state object are not mappable to JSON objects, the serialization process may transform these parts of your state in unexpected ways. For example, the javascript [Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set) type does not exist in JSON. When you try to serialize a Set via `JSON.stringify()`, it gets converted to an empty object. Probably not what you want. |
||||
|
||||
Below is a Transform that successfully persists a Set property, which simply converts it to an array and back. In this way, the Set gets converted to an Array, which is a recognized data structure in JSON. When pulled out of the persisted store, the array gets converted back to a Set before being saved to the redux store. |
||||
|
||||
```js |
||||
import { createTransform } from 'redux-persist'; |
||||
|
||||
const SetTransform = createTransform( |
||||
// transform state on its way to being serialized and persisted. |
||||
(inboundState, key) => { |
||||
// convert mySet to an Array. |
||||
return { ...inboundState, mySet: [...inboundState.mySet] }; |
||||
}, |
||||
// transform state being rehydrated |
||||
(outboundState, key) => { |
||||
// convert mySet back to a Set. |
||||
return { ...outboundState, mySet: new Set(outboundState.mySet) }; |
||||
}, |
||||
// define which reducers this transform gets called for. |
||||
{ whitelist: ['someReducer'] } |
||||
); |
||||
|
||||
export default SetTransform; |
||||
``` |
||||
|
||||
The `createTransform` function takes three parameters. |
||||
1. An "inbound" function that gets called right before state is persisted (optional). |
||||
2. An "outbound" function that gets called right before state is rehydrated (optional). |
||||
3. A config object that determines which keys in your state will be transformed (by default no keys are transformed). |
||||
|
||||
In order to take effect transforms need to be added to a `PersistReducer`’s config object. |
||||
|
||||
``` |
||||
import storage from 'redux-persist/lib/storage'; |
||||
import { SetTransform } from './transforms'; |
||||
|
||||
const persistConfig = { |
||||
key: 'root', |
||||
storage: storage, |
||||
transforms: [SetTransform] |
||||
}; |
||||
``` |
||||
|
||||
## Storage Engines |
||||
- **localStorage** `import storage from 'redux-persist/lib/storage'` |
||||
- **sessionStorage** `import storageSession from 'redux-persist/lib/storage/session'` |
||||
- **AsyncStorage** react-native `import AsyncStorage from '@react-native-community/async-storage'` |
||||
- **[localForage](https://github.com/mozilla/localForage)** recommended for web |
||||
- **[electron storage](https://github.com/psperber/redux-persist-electron-storage)** Electron support via [electron store](https://github.com/sindresorhus/electron-store) |
||||
- **[redux-persist-filesystem-storage](https://github.com/robwalkerco/redux-persist-filesystem-storage)** react-native, to mitigate storage size limitations in android ([#199](https://github.com/rt2zz/redux-persist/issues/199), [#284](https://github.com/rt2zz/redux-persist/issues/284)) |
||||
- **[redux-persist-node-storage](https://github.com/pellejacobs/redux-persist-node-storage)** for use in nodejs environments. |
||||
- **[redux-persist-sensitive-storage](https://github.com/CodingZeal/redux-persist-sensitive-storage)** react-native, for sensitive information (uses [react-native-sensitive-info](https://github.com/mCodex/react-native-sensitive-info)). |
||||
- **[redux-persist-expo-filesystem](https://github.com/t73liu/redux-persist-expo-filesystem)** react-native, similar to redux-persist-filesystem-storage but does not require linking or ejecting CRNA/Expo app. Only available if using Expo SDK (Expo, create-react-native-app, standalone). |
||||
- **[redux-persist-expo-securestore](https://github.com/Cretezy/redux-persist-expo-securestore)** react-native, for sensitive information using Expo's SecureStore. Only available if using Expo SDK (Expo, create-react-native-app, standalone). |
||||
- **[redux-persist-fs-storage](https://github.com/leethree/redux-persist-fs-storage)** react-native-fs engine |
||||
- **[redux-persist-cookie-storage](https://github.com/abersager/redux-persist-cookie-storage)** Cookie storage engine, works in browser and Node.js, for universal / isomorphic apps |
||||
- **[redux-persist-weapp-storage](https://github.com/cuijiemmx/redux-casa/tree/master/packages/redux-persist-weapp-storage)** Storage engine for wechat mini program, also compatible with wepy |
||||
- **[redux-persist-webextension-storage](https://github.com/ssorallen/redux-persist-webextension-storage)** Storage engine for browser (Chrome, Firefox) web extension storage |
||||
- **[@bankify/redux-persist-realm](https://github.com/bankifyio/redux-persist-realm)** Storage engine for Realm database, you will need to install Realm first |
||||
- **[redux-persist-pouchdb](https://github.com/yanick/redux-persist-pouchdb)** Storage engine for PouchDB. |
||||
- **custom** any conforming storage api implementing the following methods: `setItem` `getItem` `removeItem`. (**NB**: These methods must support promises) |
||||
|
||||
## Community |
||||
|
||||
### Chat Room |
||||
|
||||
[](https://discord.gg/ExrEvmv) #redux-persist channel in the [Reactiflux](https://www.reactiflux.com/) Discord |
||||
|
||||
### Blog articles from the community |
||||
|
||||
* [The Definitive Guide to Redux Persist: Persist your Redux state in between app launches with Redux Persist](https://blog.reactnativecoach.com/the-definitive-guide-to-redux-persist-84738167975) by Mark Newton |
||||
* [Redux-persist: The Good Parts](https://codeburst.io/redux-persist-the-good-parts-adfab9f91c3b) by Feargal Walsh |
||||
* [Redux: Persist Your State](https://medium.com/async-la/redux-persist-your-state-7ad346c4dd07) by Zack |
||||
* [{Persist}ence is Key: Using Redux-Persist to Store Your State in LocalStorage](https://medium.com/@clrksanford/persist-ence-is-key-using-redux-persist-to-store-your-state-in-localstorage-ac6a000aee63) by Clark Sanford |
||||
* [How to use Redux Persist when migrating your states](https://medium.freecodecamp.org/how-to-use-redux-persist-when-migrating-your-states-a5dee16b5ead) by Lusan Das |
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,8 @@ |
||||
export var KEY_PREFIX = 'persist:'; |
||||
export var FLUSH = 'persist/FLUSH'; |
||||
export var REHYDRATE = 'persist/REHYDRATE'; |
||||
export var PAUSE = 'persist/PAUSE'; |
||||
export var PERSIST = 'persist/PERSIST'; |
||||
export var PURGE = 'persist/PURGE'; |
||||
export var REGISTER = 'persist/REGISTER'; |
||||
export var DEFAULT_VERSION = -1; |
||||
@ -0,0 +1,10 @@ |
||||
// @flow |
||||
|
||||
export const KEY_PREFIX = 'persist:' |
||||
export const FLUSH = 'persist/FLUSH' |
||||
export const REHYDRATE = 'persist/REHYDRATE' |
||||
export const PAUSE = 'persist/PAUSE' |
||||
export const PERSIST = 'persist/PERSIST' |
||||
export const PURGE = 'persist/PURGE' |
||||
export const REGISTER = 'persist/REGISTER' |
||||
export const DEFAULT_VERSION = -1 |
||||
@ -0,0 +1,43 @@ |
||||
import { DEFAULT_VERSION } from './constants'; |
||||
export default function createMigrate(migrations, config) { |
||||
var _ref = config || {}, |
||||
debug = _ref.debug; |
||||
|
||||
return function (state, currentVersion) { |
||||
if (!state) { |
||||
if (process.env.NODE_ENV !== 'production' && debug) console.log('redux-persist: no inbound state, skipping migration'); |
||||
return Promise.resolve(undefined); |
||||
} |
||||
|
||||
var inboundVersion = state._persist && state._persist.version !== undefined ? state._persist.version : DEFAULT_VERSION; |
||||
|
||||
if (inboundVersion === currentVersion) { |
||||
if (process.env.NODE_ENV !== 'production' && debug) console.log('redux-persist: versions match, noop migration'); |
||||
return Promise.resolve(state); |
||||
} |
||||
|
||||
if (inboundVersion > currentVersion) { |
||||
if (process.env.NODE_ENV !== 'production') console.error('redux-persist: downgrading version is not supported'); |
||||
return Promise.resolve(state); |
||||
} |
||||
|
||||
var migrationKeys = Object.keys(migrations).map(function (ver) { |
||||
return parseInt(ver); |
||||
}).filter(function (key) { |
||||
return currentVersion >= key && key > inboundVersion; |
||||
}).sort(function (a, b) { |
||||
return a - b; |
||||
}); |
||||
if (process.env.NODE_ENV !== 'production' && debug) console.log('redux-persist: migrationKeys', migrationKeys); |
||||
|
||||
try { |
||||
var migratedState = migrationKeys.reduce(function (state, versionKey) { |
||||
if (process.env.NODE_ENV !== 'production' && debug) console.log('redux-persist: running migration for versionKey', versionKey); |
||||
return migrations[versionKey](state); |
||||
}, state); |
||||
return Promise.resolve(migratedState); |
||||
} catch (err) { |
||||
return Promise.reject(err); |
||||
} |
||||
}; |
||||
} |
||||
@ -0,0 +1,58 @@ |
||||
// @flow |
||||
|
||||
import { DEFAULT_VERSION } from './constants' |
||||
|
||||
import type { PersistedState, MigrationManifest } from './types' |
||||
|
||||
export default function createMigrate( |
||||
migrations: MigrationManifest, |
||||
config?: { debug: boolean } |
||||
) { |
||||
let { debug } = config || {} |
||||
return function( |
||||
state: PersistedState, |
||||
currentVersion: number |
||||
): Promise<PersistedState> { |
||||
if (!state) { |
||||
if (process.env.NODE_ENV !== 'production' && debug) |
||||
console.log('redux-persist: no inbound state, skipping migration') |
||||
return Promise.resolve(undefined) |
||||
} |
||||
|
||||
let inboundVersion: number = |
||||
state._persist && state._persist.version !== undefined |
||||
? state._persist.version |
||||
: DEFAULT_VERSION |
||||
if (inboundVersion === currentVersion) { |
||||
if (process.env.NODE_ENV !== 'production' && debug) |
||||
console.log('redux-persist: versions match, noop migration') |
||||
return Promise.resolve(state) |
||||
} |
||||
if (inboundVersion > currentVersion) { |
||||
if (process.env.NODE_ENV !== 'production') |
||||
console.error('redux-persist: downgrading version is not supported') |
||||
return Promise.resolve(state) |
||||
} |
||||
|
||||
let migrationKeys = Object.keys(migrations) |
||||
.map(ver => parseInt(ver)) |
||||
.filter(key => currentVersion >= key && key > inboundVersion) |
||||
.sort((a, b) => a - b) |
||||
|
||||
if (process.env.NODE_ENV !== 'production' && debug) |
||||
console.log('redux-persist: migrationKeys', migrationKeys) |
||||
try { |
||||
let migratedState = migrationKeys.reduce((state, versionKey) => { |
||||
if (process.env.NODE_ENV !== 'production' && debug) |
||||
console.log( |
||||
'redux-persist: running migration for versionKey', |
||||
versionKey |
||||
) |
||||
return migrations[versionKey](state) |
||||
}, state) |
||||
return Promise.resolve(migratedState) |
||||
} catch (err) { |
||||
return Promise.reject(err) |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,127 @@ |
||||
import { KEY_PREFIX, REHYDRATE } from './constants'; |
||||
// @TODO remove once flow < 0.63 support is no longer required.
|
||||
export default function createPersistoid(config) { |
||||
// defaults
|
||||
var blacklist = config.blacklist || null; |
||||
var whitelist = config.whitelist || null; |
||||
var transforms = config.transforms || []; |
||||
var throttle = config.throttle || 0; |
||||
var storageKey = "".concat(config.keyPrefix !== undefined ? config.keyPrefix : KEY_PREFIX).concat(config.key); |
||||
var storage = config.storage; |
||||
var serialize; |
||||
|
||||
if (config.serialize === false) { |
||||
serialize = function serialize(x) { |
||||
return x; |
||||
}; |
||||
} else if (typeof config.serialize === 'function') { |
||||
serialize = config.serialize; |
||||
} else { |
||||
serialize = defaultSerialize; |
||||
} |
||||
|
||||
var writeFailHandler = config.writeFailHandler || null; // initialize stateful values
|
||||
|
||||
var lastState = {}; |
||||
var stagedState = {}; |
||||
var keysToProcess = []; |
||||
var timeIterator = null; |
||||
var writePromise = null; |
||||
|
||||
var update = function update(state) { |
||||
// add any changed keys to the queue
|
||||
Object.keys(state).forEach(function (key) { |
||||
if (!passWhitelistBlacklist(key)) return; // is keyspace ignored? noop
|
||||
|
||||
if (lastState[key] === state[key]) return; // value unchanged? noop
|
||||
|
||||
if (keysToProcess.indexOf(key) !== -1) return; // is key already queued? noop
|
||||
|
||||
keysToProcess.push(key); // add key to queue
|
||||
}); //if any key is missing in the new state which was present in the lastState,
|
||||
//add it for processing too
|
||||
|
||||
Object.keys(lastState).forEach(function (key) { |
||||
if (state[key] === undefined && passWhitelistBlacklist(key) && keysToProcess.indexOf(key) === -1 && lastState[key] !== undefined) { |
||||
keysToProcess.push(key); |
||||
} |
||||
}); // start the time iterator if not running (read: throttle)
|
||||
|
||||
if (timeIterator === null) { |
||||
timeIterator = setInterval(processNextKey, throttle); |
||||
} |
||||
|
||||
lastState = state; |
||||
}; |
||||
|
||||
function processNextKey() { |
||||
if (keysToProcess.length === 0) { |
||||
if (timeIterator) clearInterval(timeIterator); |
||||
timeIterator = null; |
||||
return; |
||||
} |
||||
|
||||
var key = keysToProcess.shift(); |
||||
var endState = transforms.reduce(function (subState, transformer) { |
||||
return transformer.in(subState, key, lastState); |
||||
}, lastState[key]); |
||||
|
||||
if (endState !== undefined) { |
||||
try { |
||||
stagedState[key] = serialize(endState); |
||||
} catch (err) { |
||||
console.error('redux-persist/createPersistoid: error serializing state', err); |
||||
} |
||||
} else { |
||||
//if the endState is undefined, no need to persist the existing serialized content
|
||||
delete stagedState[key]; |
||||
} |
||||
|
||||
if (keysToProcess.length === 0) { |
||||
writeStagedState(); |
||||
} |
||||
} |
||||
|
||||
function writeStagedState() { |
||||
// cleanup any removed keys just before write.
|
||||
Object.keys(stagedState).forEach(function (key) { |
||||
if (lastState[key] === undefined) { |
||||
delete stagedState[key]; |
||||
} |
||||
}); |
||||
writePromise = storage.setItem(storageKey, serialize(stagedState)).catch(onWriteFail); |
||||
} |
||||
|
||||
function passWhitelistBlacklist(key) { |
||||
if (whitelist && whitelist.indexOf(key) === -1 && key !== '_persist') return false; |
||||
if (blacklist && blacklist.indexOf(key) !== -1) return false; |
||||
return true; |
||||
} |
||||
|
||||
function onWriteFail(err) { |
||||
// @TODO add fail handlers (typically storage full)
|
||||
if (writeFailHandler) writeFailHandler(err); |
||||
|
||||
if (err && process.env.NODE_ENV !== 'production') { |
||||
console.error('Error storing data', err); |
||||
} |
||||
} |
||||
|
||||
var flush = function flush() { |
||||
while (keysToProcess.length !== 0) { |
||||
processNextKey(); |
||||
} |
||||
|
||||
return writePromise || Promise.resolve(); |
||||
}; // return `persistoid`
|
||||
|
||||
|
||||
return { |
||||
update: update, |
||||
flush: flush |
||||
}; |
||||
} // @NOTE in the future this may be exposed via config
|
||||
|
||||
function defaultSerialize(data) { |
||||
return JSON.stringify(data); |
||||
} |
||||
@ -0,0 +1,142 @@ |
||||
// @flow |
||||
|
||||
import { KEY_PREFIX, REHYDRATE } from './constants' |
||||
|
||||
import type { Persistoid, PersistConfig, Transform } from './types' |
||||
|
||||
type IntervalID = any // @TODO remove once flow < 0.63 support is no longer required. |
||||
|
||||
export default function createPersistoid(config: PersistConfig): Persistoid { |
||||
// defaults |
||||
const blacklist: ?Array<string> = config.blacklist || null |
||||
const whitelist: ?Array<string> = config.whitelist || null |
||||
const transforms = config.transforms || [] |
||||
const throttle = config.throttle || 0 |
||||
const storageKey = `${ |
||||
config.keyPrefix !== undefined ? config.keyPrefix : KEY_PREFIX |
||||
}${config.key}` |
||||
const storage = config.storage |
||||
let serialize |
||||
if (config.serialize === false) { |
||||
serialize = x => x |
||||
} else if (typeof config.serialize === 'function') { |
||||
serialize = config.serialize |
||||
} else { |
||||
serialize = defaultSerialize |
||||
} |
||||
const writeFailHandler = config.writeFailHandler || null |
||||
|
||||
// initialize stateful values |
||||
let lastState = {} |
||||
let stagedState = {} |
||||
let keysToProcess = [] |
||||
let timeIterator: ?IntervalID = null |
||||
let writePromise = null |
||||
|
||||
const update = (state: Object) => { |
||||
// add any changed keys to the queue |
||||
Object.keys(state).forEach(key => { |
||||
if (!passWhitelistBlacklist(key)) return // is keyspace ignored? noop |
||||
if (lastState[key] === state[key]) return // value unchanged? noop |
||||
if (keysToProcess.indexOf(key) !== -1) return // is key already queued? noop |
||||
keysToProcess.push(key) // add key to queue |
||||
}) |
||||
|
||||
//if any key is missing in the new state which was present in the lastState, |
||||
//add it for processing too |
||||
Object.keys(lastState).forEach(key => { |
||||
if ( |
||||
state[key] === undefined && |
||||
passWhitelistBlacklist(key) && |
||||
keysToProcess.indexOf(key) === -1 && |
||||
lastState[key] !== undefined |
||||
) { |
||||
keysToProcess.push(key) |
||||
} |
||||
}) |
||||
|
||||
// start the time iterator if not running (read: throttle) |
||||
if (timeIterator === null) { |
||||
timeIterator = setInterval(processNextKey, throttle) |
||||
} |
||||
|
||||
lastState = state |
||||
} |
||||
|
||||
function processNextKey() { |
||||
if (keysToProcess.length === 0) { |
||||
if (timeIterator) clearInterval(timeIterator) |
||||
timeIterator = null |
||||
return |
||||
} |
||||
|
||||
let key = keysToProcess.shift() |
||||
let endState = transforms.reduce((subState, transformer) => { |
||||
return transformer.in(subState, key, lastState) |
||||
}, lastState[key]) |
||||
|
||||
if (endState !== undefined) { |
||||
try { |
||||
stagedState[key] = serialize(endState) |
||||
} catch (err) { |
||||
console.error( |
||||
'redux-persist/createPersistoid: error serializing state', |
||||
err |
||||
) |
||||
} |
||||
} else { |
||||
//if the endState is undefined, no need to persist the existing serialized content |
||||
delete stagedState[key] |
||||
} |
||||
|
||||
if (keysToProcess.length === 0) { |
||||
writeStagedState() |
||||
} |
||||
} |
||||
|
||||
function writeStagedState() { |
||||
// cleanup any removed keys just before write. |
||||
Object.keys(stagedState).forEach(key => { |
||||
if (lastState[key] === undefined) { |
||||
delete stagedState[key] |
||||
} |
||||
}) |
||||
|
||||
writePromise = storage |
||||
.setItem(storageKey, serialize(stagedState)) |
||||
.catch(onWriteFail) |
||||
} |
||||
|
||||
function passWhitelistBlacklist(key) { |
||||
if (whitelist && whitelist.indexOf(key) === -1 && key !== '_persist') |
||||
return false |
||||
if (blacklist && blacklist.indexOf(key) !== -1) return false |
||||
return true |
||||
} |
||||
|
||||
function onWriteFail(err) { |
||||
// @TODO add fail handlers (typically storage full) |
||||
if (writeFailHandler) writeFailHandler(err) |
||||
if (err && process.env.NODE_ENV !== 'production') { |
||||
console.error('Error storing data', err) |
||||
} |
||||
} |
||||
|
||||
const flush = () => { |
||||
while (keysToProcess.length !== 0) { |
||||
processNextKey() |
||||
} |
||||
return writePromise || Promise.resolve() |
||||
} |
||||
|
||||
// return `persistoid` |
||||
return { |
||||
update, |
||||
flush, |
||||
} |
||||
} |
||||
|
||||
// @NOTE in the future this may be exposed via config |
||||
function defaultSerialize(data) { |
||||
return JSON.stringify(data) |
||||
} |
||||
@ -0,0 +1,22 @@ |
||||
export default function createTransform( // @NOTE inbound: transform state coming from redux on its way to being serialized and stored
|
||||
inbound, // @NOTE outbound: transform state coming from storage, on its way to be rehydrated into redux
|
||||
outbound) { |
||||
var config = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; |
||||
var whitelist = config.whitelist || null; |
||||
var blacklist = config.blacklist || null; |
||||
|
||||
function whitelistBlacklistCheck(key) { |
||||
if (whitelist && whitelist.indexOf(key) === -1) return true; |
||||
if (blacklist && blacklist.indexOf(key) !== -1) return true; |
||||
return false; |
||||
} |
||||
|
||||
return { |
||||
in: function _in(state, key, fullState) { |
||||
return !whitelistBlacklistCheck(key) && inbound ? inbound(state, key, fullState) : state; |
||||
}, |
||||
out: function out(state, key, fullState) { |
||||
return !whitelistBlacklistCheck(key) && outbound ? outbound(state, key, fullState) : state; |
||||
} |
||||
}; |
||||
} |
||||
@ -0,0 +1,34 @@ |
||||
// @flow |
||||
|
||||
type TransformConfig = { |
||||
whitelist?: Array<string>, |
||||
blacklist?: Array<string>, |
||||
} |
||||
|
||||
export default function createTransform( |
||||
// @NOTE inbound: transform state coming from redux on its way to being serialized and stored |
||||
inbound: ?Function, |
||||
// @NOTE outbound: transform state coming from storage, on its way to be rehydrated into redux |
||||
outbound: ?Function, |
||||
config: TransformConfig = {} |
||||
) { |
||||
let whitelist = config.whitelist || null |
||||
let blacklist = config.blacklist || null |
||||
|
||||
function whitelistBlacklistCheck(key) { |
||||
if (whitelist && whitelist.indexOf(key) === -1) return true |
||||
if (blacklist && blacklist.indexOf(key) !== -1) return true |
||||
return false |
||||
} |
||||
|
||||
return { |
||||
in: (state: Object, key: string, fullState: Object) => |
||||
!whitelistBlacklistCheck(key) && inbound |
||||
? inbound(state, key, fullState) |
||||
: state, |
||||
out: (state: Object, key: string, fullState: Object) => |
||||
!whitelistBlacklistCheck(key) && outbound |
||||
? outbound(state, key, fullState) |
||||
: state, |
||||
} |
||||
} |
||||
@ -0,0 +1,40 @@ |
||||
import { KEY_PREFIX } from './constants'; |
||||
export default function getStoredState(config) { |
||||
var transforms = config.transforms || []; |
||||
var storageKey = "".concat(config.keyPrefix !== undefined ? config.keyPrefix : KEY_PREFIX).concat(config.key); |
||||
var storage = config.storage; |
||||
var debug = config.debug; |
||||
var deserialize; |
||||
|
||||
if (config.deserialize === false) { |
||||
deserialize = function deserialize(x) { |
||||
return x; |
||||
}; |
||||
} else if (typeof config.deserialize === 'function') { |
||||
deserialize = config.deserialize; |
||||
} else { |
||||
deserialize = defaultDeserialize; |
||||
} |
||||
|
||||
return storage.getItem(storageKey).then(function (serialized) { |
||||
if (!serialized) return undefined;else { |
||||
try { |
||||
var state = {}; |
||||
var rawState = deserialize(serialized); |
||||
Object.keys(rawState).forEach(function (key) { |
||||
state[key] = transforms.reduceRight(function (subState, transformer) { |
||||
return transformer.out(subState, key, rawState); |
||||
}, deserialize(rawState[key])); |
||||
}); |
||||
return state; |
||||
} catch (err) { |
||||
if (process.env.NODE_ENV !== 'production' && debug) console.log("redux-persist/getStoredState: Error restoring data ".concat(serialized), err); |
||||
throw err; |
||||
} |
||||
} |
||||
}); |
||||
} |
||||
|
||||
function defaultDeserialize(serial) { |
||||
return JSON.parse(serial); |
||||
} |
||||
@ -0,0 +1,50 @@ |
||||
// @flow |
||||
|
||||
import type { PersistConfig } from './types' |
||||
|
||||
import { KEY_PREFIX } from './constants' |
||||
|
||||
export default function getStoredState( |
||||
config: PersistConfig |
||||
): Promise<Object | void> { |
||||
const transforms = config.transforms || [] |
||||
const storageKey = `${ |
||||
config.keyPrefix !== undefined ? config.keyPrefix : KEY_PREFIX |
||||
}${config.key}` |
||||
const storage = config.storage |
||||
const debug = config.debug |
||||
let deserialize |
||||
if (config.deserialize === false) { |
||||
deserialize = x => x |
||||
} else if (typeof config.deserialize === 'function') { |
||||
deserialize = config.deserialize |
||||
} else { |
||||
deserialize = defaultDeserialize |
||||
} |
||||
return storage.getItem(storageKey).then(serialized => { |
||||
if (!serialized) return undefined |
||||
else { |
||||
try { |
||||
let state = {} |
||||
let rawState = deserialize(serialized) |
||||
Object.keys(rawState).forEach(key => { |
||||
state[key] = transforms.reduceRight((subState, transformer) => { |
||||
return transformer.out(subState, key, rawState) |
||||
}, deserialize(rawState[key])) |
||||
}) |
||||
return state |
||||
} catch (err) { |
||||
if (process.env.NODE_ENV !== 'production' && debug) |
||||
console.log( |
||||
`redux-persist/getStoredState: Error restoring data ${serialized}`, |
||||
err |
||||
) |
||||
throw err |
||||
} |
||||
} |
||||
}) |
||||
} |
||||
|
||||
function defaultDeserialize(serial) { |
||||
return JSON.parse(serial) |
||||
} |
||||
@ -0,0 +1,9 @@ |
||||
export { default as persistReducer } from './persistReducer'; |
||||
export { default as persistCombineReducers } from './persistCombineReducers'; |
||||
export { default as persistStore } from './persistStore'; |
||||
export { default as createMigrate } from './createMigrate'; |
||||
export { default as createTransform } from './createTransform'; |
||||
export { default as getStoredState } from './getStoredState'; |
||||
export { default as createPersistoid } from './createPersistoid'; |
||||
export { default as purgeStoredState } from './purgeStoredState'; |
||||
export * from './constants'; |
||||
@ -0,0 +1,12 @@ |
||||
// @flow |
||||
|
||||
export { default as persistReducer } from './persistReducer' |
||||
export { default as persistCombineReducers } from './persistCombineReducers' |
||||
export { default as persistStore } from './persistStore' |
||||
export { default as createMigrate } from './createMigrate' |
||||
export { default as createTransform } from './createTransform' |
||||
export { default as getStoredState } from './getStoredState' |
||||
export { default as createPersistoid } from './createPersistoid' |
||||
export { default as purgeStoredState } from './purgeStoredState' |
||||
|
||||
export * from './constants' |
||||
@ -0,0 +1,166 @@ |
||||
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(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; } |
||||
|
||||
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; } |
||||
|
||||
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); } |
||||
|
||||
import getStoredStateV5 from '../getStoredState'; |
||||
export default function getStoredState(v4Config) { |
||||
return function (v5Config) { |
||||
return getStoredStateV5(v5Config).then(function (state) { |
||||
if (state) return state;else return getStoredStateV4(v4Config); |
||||
}); |
||||
}; |
||||
} |
||||
var KEY_PREFIX = 'reduxPersist:'; |
||||
|
||||
function hasLocalStorage() { |
||||
if ((typeof self === "undefined" ? "undefined" : _typeof(self)) !== 'object' || !('localStorage' in self)) { |
||||
return false; |
||||
} |
||||
|
||||
try { |
||||
var storage = self.localStorage; |
||||
var testKey = "redux-persist localStorage test"; |
||||
storage.setItem(testKey, 'test'); |
||||
storage.getItem(testKey); |
||||
storage.removeItem(testKey); |
||||
} catch (e) { |
||||
if (process.env.NODE_ENV !== 'production') console.warn("redux-persist localStorage test failed, persistence will be disabled."); |
||||
return false; |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
||||
var noop = function noop() { |
||||
/* noop */ |
||||
return null; |
||||
}; |
||||
|
||||
var noStorage = { |
||||
getItem: noop, |
||||
setItem: noop, |
||||
removeItem: noop, |
||||
getAllKeys: noop |
||||
}; |
||||
|
||||
var createAsyncLocalStorage = function createAsyncLocalStorage() { |
||||
if (!hasLocalStorage()) return noStorage; |
||||
var localStorage = self.localStorage; |
||||
return { |
||||
getAllKeys: function getAllKeys(cb) { |
||||
try { |
||||
var keys = []; |
||||
|
||||
for (var i = 0; i < localStorage.length; i++) { |
||||
keys.push(localStorage.key(i)); |
||||
} |
||||
|
||||
cb(null, keys); |
||||
} catch (e) { |
||||
cb(e); |
||||
} |
||||
}, |
||||
getItem: function getItem(key, cb) { |
||||
try { |
||||
var s = localStorage.getItem(key); |
||||
cb(null, s); |
||||
} catch (e) { |
||||
cb(e); |
||||
} |
||||
}, |
||||
setItem: function setItem(key, string, cb) { |
||||
try { |
||||
localStorage.setItem(key, string); |
||||
cb(null); |
||||
} catch (e) { |
||||
cb(e); |
||||
} |
||||
}, |
||||
removeItem: function removeItem(key, cb) { |
||||
try { |
||||
localStorage.removeItem(key); |
||||
cb && cb(null); |
||||
} catch (e) { |
||||
cb(e); |
||||
} |
||||
} |
||||
}; |
||||
}; |
||||
|
||||
function getStoredStateV4(v4Config) { |
||||
return new Promise(function (resolve, reject) { |
||||
var storage = v4Config.storage || createAsyncLocalStorage(); |
||||
var deserializer = v4Config.serialize === false ? function (data) { |
||||
return data; |
||||
} : function (serial) { |
||||
return JSON.parse(serial); |
||||
}; |
||||
var blacklist = v4Config.blacklist || []; |
||||
var whitelist = v4Config.whitelist || false; |
||||
var transforms = v4Config.transforms || []; |
||||
var keyPrefix = v4Config.keyPrefix !== undefined ? v4Config.keyPrefix : KEY_PREFIX; // fallback getAllKeys to `keys` if present (LocalForage compatability)
|
||||
|
||||
if (storage.keys && !storage.getAllKeys) storage = _objectSpread({}, storage, { |
||||
getAllKeys: storage.keys |
||||
}); |
||||
var restoredState = {}; |
||||
var completionCount = 0; |
||||
storage.getAllKeys(function (err) { |
||||
var allKeys = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; |
||||
|
||||
if (err) { |
||||
if (process.env.NODE_ENV !== 'production') console.warn('redux-persist/getStoredState: Error in storage.getAllKeys'); |
||||
return reject(err); |
||||
} |
||||
|
||||
var persistKeys = allKeys.filter(function (key) { |
||||
return key.indexOf(keyPrefix) === 0; |
||||
}).map(function (key) { |
||||
return key.slice(keyPrefix.length); |
||||
}); |
||||
var keysToRestore = persistKeys.filter(passWhitelistBlacklist); |
||||
var restoreCount = keysToRestore.length; |
||||
if (restoreCount === 0) resolve(undefined); |
||||
keysToRestore.forEach(function (key) { |
||||
storage.getItem(createStorageKey(key), function (err, serialized) { |
||||
if (err && process.env.NODE_ENV !== 'production') console.warn('redux-persist/getStoredState: Error restoring data for key:', key, err);else restoredState[key] = rehydrate(key, serialized); |
||||
completionCount += 1; |
||||
if (completionCount === restoreCount) resolve(restoredState); |
||||
}); |
||||
}); |
||||
}); |
||||
|
||||
function rehydrate(key, serialized) { |
||||
var state = null; |
||||
|
||||
try { |
||||
var data = serialized ? deserializer(serialized) : undefined; |
||||
state = transforms.reduceRight(function (subState, transformer) { |
||||
return transformer.out(subState, key, {}); |
||||
}, data); |
||||
} catch (err) { |
||||
if (process.env.NODE_ENV !== 'production') console.warn('redux-persist/getStoredState: Error restoring data for key:', key, err); |
||||
} |
||||
|
||||
return state; |
||||
} |
||||
|
||||
function passWhitelistBlacklist(key) { |
||||
if (whitelist && whitelist.indexOf(key) === -1) return false; |
||||
if (blacklist.indexOf(key) !== -1) return false; |
||||
return true; |
||||
} |
||||
|
||||
function createStorageKey(key) { |
||||
return "".concat(keyPrefix).concat(key); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
function defaultDeserializer(serial) { |
||||
return JSON.parse(serial); |
||||
} |
||||
@ -0,0 +1,184 @@ |
||||
// @flow |
||||
|
||||
import getStoredStateV5 from '../getStoredState' |
||||
|
||||
import type { PersistConfig, Transform } from '../types' |
||||
|
||||
type V4Config = { |
||||
storage?: Object, |
||||
serialize: boolean, |
||||
keyPrefix?: string, |
||||
transforms?: Array<Transform>, |
||||
blacklist?: Array<string>, |
||||
whitelist?: Array<string>, |
||||
} |
||||
|
||||
export default function getStoredState(v4Config: V4Config) { |
||||
return function(v5Config: PersistConfig) { |
||||
return getStoredStateV5(v5Config).then(state => { |
||||
if (state) return state |
||||
else return getStoredStateV4(v4Config) |
||||
}) |
||||
} |
||||
} |
||||
|
||||
const KEY_PREFIX = 'reduxPersist:' |
||||
|
||||
function hasLocalStorage() { |
||||
if (typeof self !== 'object' || !('localStorage' in self)) { |
||||
return false |
||||
} |
||||
|
||||
try { |
||||
let storage = self.localStorage |
||||
const testKey = `redux-persist localStorage test` |
||||
storage.setItem(testKey, 'test') |
||||
storage.getItem(testKey) |
||||
storage.removeItem(testKey) |
||||
} catch (e) { |
||||
if (process.env.NODE_ENV !== 'production') |
||||
console.warn( |
||||
`redux-persist localStorage test failed, persistence will be disabled.` |
||||
) |
||||
return false |
||||
} |
||||
return true |
||||
} |
||||
|
||||
let noop = (...args: any) => { |
||||
/* noop */ return null |
||||
} |
||||
const noStorage = { |
||||
getItem: noop, |
||||
setItem: noop, |
||||
removeItem: noop, |
||||
getAllKeys: noop, |
||||
} |
||||
const createAsyncLocalStorage = () => { |
||||
if (!hasLocalStorage()) return noStorage |
||||
let localStorage = self.localStorage |
||||
return { |
||||
getAllKeys: function(cb) { |
||||
try { |
||||
var keys = [] |
||||
for (var i = 0; i < localStorage.length; i++) { |
||||
keys.push(localStorage.key(i)) |
||||
} |
||||
cb(null, keys) |
||||
} catch (e) { |
||||
cb(e) |
||||
} |
||||
}, |
||||
getItem(key, cb) { |
||||
try { |
||||
var s = localStorage.getItem(key) |
||||
cb(null, s) |
||||
} catch (e) { |
||||
cb(e) |
||||
} |
||||
}, |
||||
setItem(key, string, cb) { |
||||
try { |
||||
localStorage.setItem(key, string) |
||||
cb(null) |
||||
} catch (e) { |
||||
cb(e) |
||||
} |
||||
}, |
||||
removeItem(key, cb) { |
||||
try { |
||||
localStorage.removeItem(key) |
||||
cb && cb(null) |
||||
} catch (e) { |
||||
cb(e) |
||||
} |
||||
}, |
||||
} |
||||
} |
||||
|
||||
function getStoredStateV4(v4Config: V4Config) { |
||||
return new Promise((resolve, reject) => { |
||||
let storage = v4Config.storage || createAsyncLocalStorage() |
||||
const deserializer = |
||||
v4Config.serialize === false |
||||
? data => data |
||||
: (serial: string) => JSON.parse(serial) |
||||
const blacklist = v4Config.blacklist || [] |
||||
const whitelist = v4Config.whitelist || false |
||||
const transforms = v4Config.transforms || [] |
||||
const keyPrefix = |
||||
v4Config.keyPrefix !== undefined ? v4Config.keyPrefix : KEY_PREFIX |
||||
|
||||
// fallback getAllKeys to `keys` if present (LocalForage compatability) |
||||
if (storage.keys && !storage.getAllKeys) |
||||
storage = { ...storage, getAllKeys: storage.keys } |
||||
|
||||
let restoredState = {} |
||||
let completionCount = 0 |
||||
|
||||
storage.getAllKeys((err, allKeys = []) => { |
||||
if (err) { |
||||
if (process.env.NODE_ENV !== 'production') |
||||
console.warn( |
||||
'redux-persist/getStoredState: Error in storage.getAllKeys' |
||||
) |
||||
return reject(err) |
||||
} |
||||
|
||||
let persistKeys = allKeys |
||||
.filter(key => key.indexOf(keyPrefix) === 0) |
||||
.map(key => key.slice(keyPrefix.length)) |
||||
let keysToRestore = persistKeys.filter(passWhitelistBlacklist) |
||||
|
||||
let restoreCount = keysToRestore.length |
||||
if (restoreCount === 0) resolve(undefined) |
||||
keysToRestore.forEach(key => { |
||||
storage.getItem(createStorageKey(key), (err, serialized) => { |
||||
if (err && process.env.NODE_ENV !== 'production') |
||||
console.warn( |
||||
'redux-persist/getStoredState: Error restoring data for key:', |
||||
key, |
||||
err |
||||
) |
||||
else restoredState[key] = rehydrate(key, serialized) |
||||
completionCount += 1 |
||||
if (completionCount === restoreCount) resolve(restoredState) |
||||
}) |
||||
}) |
||||
}) |
||||
|
||||
function rehydrate(key: string, serialized: ?string) { |
||||
let state = null |
||||
|
||||
try { |
||||
let data = serialized ? deserializer(serialized) : undefined |
||||
state = transforms.reduceRight((subState, transformer) => { |
||||
return transformer.out(subState, key, {}) |
||||
}, data) |
||||
} catch (err) { |
||||
if (process.env.NODE_ENV !== 'production') |
||||
console.warn( |
||||
'redux-persist/getStoredState: Error restoring data for key:', |
||||
key, |
||||
err |
||||
) |
||||
} |
||||
|
||||
return state |
||||
} |
||||
|
||||
function passWhitelistBlacklist(key) { |
||||
if (whitelist && whitelist.indexOf(key) === -1) return false |
||||
if (blacklist.indexOf(key) !== -1) return false |
||||
return true |
||||
} |
||||
|
||||
function createStorageKey(key) { |
||||
return `${keyPrefix}${key}` |
||||
} |
||||
}) |
||||
} |
||||
|
||||
function defaultDeserializer(serial: string) { |
||||
return JSON.parse(serial) |
||||
} |
||||
@ -0,0 +1,105 @@ |
||||
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); } |
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } |
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } |
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } |
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } |
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } |
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } |
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } |
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } |
||||
|
||||
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; } |
||||
|
||||
import React, { PureComponent } from 'react'; // eslint-disable-line import/no-unresolved
|
||||
|
||||
export var PersistGate = |
||||
/*#__PURE__*/ |
||||
function (_PureComponent) { |
||||
_inherits(PersistGate, _PureComponent); |
||||
|
||||
function PersistGate() { |
||||
var _getPrototypeOf2; |
||||
|
||||
var _this; |
||||
|
||||
_classCallCheck(this, PersistGate); |
||||
|
||||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { |
||||
args[_key] = arguments[_key]; |
||||
} |
||||
|
||||
_this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(PersistGate)).call.apply(_getPrototypeOf2, [this].concat(args))); |
||||
|
||||
_defineProperty(_assertThisInitialized(_this), "state", { |
||||
bootstrapped: false |
||||
}); |
||||
|
||||
_defineProperty(_assertThisInitialized(_this), "_unsubscribe", void 0); |
||||
|
||||
_defineProperty(_assertThisInitialized(_this), "handlePersistorState", function () { |
||||
var persistor = _this.props.persistor; |
||||
|
||||
var _persistor$getState = persistor.getState(), |
||||
bootstrapped = _persistor$getState.bootstrapped; |
||||
|
||||
if (bootstrapped) { |
||||
if (_this.props.onBeforeLift) { |
||||
Promise.resolve(_this.props.onBeforeLift()).finally(function () { |
||||
return _this.setState({ |
||||
bootstrapped: true |
||||
}); |
||||
}); |
||||
} else { |
||||
_this.setState({ |
||||
bootstrapped: true |
||||
}); |
||||
} |
||||
|
||||
_this._unsubscribe && _this._unsubscribe(); |
||||
} |
||||
}); |
||||
|
||||
return _this; |
||||
} |
||||
|
||||
_createClass(PersistGate, [{ |
||||
key: "componentDidMount", |
||||
value: function componentDidMount() { |
||||
this._unsubscribe = this.props.persistor.subscribe(this.handlePersistorState); |
||||
this.handlePersistorState(); |
||||
} |
||||
}, { |
||||
key: "componentWillUnmount", |
||||
value: function componentWillUnmount() { |
||||
this._unsubscribe && this._unsubscribe(); |
||||
} |
||||
}, { |
||||
key: "render", |
||||
value: function render() { |
||||
if (process.env.NODE_ENV !== 'production') { |
||||
if (typeof this.props.children === 'function' && this.props.loading) console.error('redux-persist: PersistGate expects either a function child or loading prop, but not both. The loading prop will be ignored.'); |
||||
} |
||||
|
||||
if (typeof this.props.children === 'function') { |
||||
return this.props.children(this.state.bootstrapped); |
||||
} |
||||
|
||||
return this.state.bootstrapped ? this.props.children : this.props.loading; |
||||
} |
||||
}]); |
||||
|
||||
return PersistGate; |
||||
}(PureComponent); |
||||
|
||||
_defineProperty(PersistGate, "defaultProps", { |
||||
children: null, |
||||
loading: null |
||||
}); |
||||
@ -0,0 +1,66 @@ |
||||
// @flow |
||||
import React, { PureComponent } from 'react' // eslint-disable-line import/no-unresolved |
||||
import type { Node } from 'react' // eslint-disable-line import/no-unresolved |
||||
import type { Persistor } from '../types' |
||||
|
||||
type Props = { |
||||
onBeforeLift?: Function, |
||||
children: Node | Function, |
||||
loading: Node, |
||||
persistor: Persistor, |
||||
} |
||||
|
||||
type State = { |
||||
bootstrapped: boolean, |
||||
} |
||||
|
||||
export class PersistGate extends PureComponent<Props, State> { |
||||
static defaultProps = { |
||||
children: null, |
||||
loading: null, |
||||
} |
||||
|
||||
state = { |
||||
bootstrapped: false, |
||||
} |
||||
_unsubscribe: ?Function |
||||
|
||||
componentDidMount() { |
||||
this._unsubscribe = this.props.persistor.subscribe( |
||||
this.handlePersistorState |
||||
) |
||||
this.handlePersistorState() |
||||
} |
||||
|
||||
handlePersistorState = () => { |
||||
const { persistor } = this.props |
||||
let { bootstrapped } = persistor.getState() |
||||
if (bootstrapped) { |
||||
if (this.props.onBeforeLift) { |
||||
Promise.resolve(this.props.onBeforeLift()) |
||||
.finally(() => this.setState({ bootstrapped: true })) |
||||
} else { |
||||
this.setState({ bootstrapped: true }) |
||||
} |
||||
this._unsubscribe && this._unsubscribe() |
||||
} |
||||
} |
||||
|
||||
componentWillUnmount() { |
||||
this._unsubscribe && this._unsubscribe() |
||||
} |
||||
|
||||
render() { |
||||
if (process.env.NODE_ENV !== 'production') { |
||||
if (typeof this.props.children === 'function' && this.props.loading) |
||||
console.error( |
||||
'redux-persist: PersistGate expects either a function child or loading prop, but not both. The loading prop will be ignored.' |
||||
) |
||||
} |
||||
if (typeof this.props.children === 'function') { |
||||
return this.props.children(this.state.bootstrapped) |
||||
} |
||||
|
||||
return this.state.bootstrapped ? this.props.children : this.props.loading |
||||
} |
||||
} |
||||
@ -0,0 +1,8 @@ |
||||
import { combineReducers } from 'redux'; |
||||
import persistReducer from './persistReducer'; |
||||
import autoMergeLevel2 from './stateReconciler/autoMergeLevel2'; |
||||
// combineReducers + persistReducer with stateReconciler defaulted to autoMergeLevel2
|
||||
export default function persistCombineReducers(config, reducers) { |
||||
config.stateReconciler = config.stateReconciler === undefined ? autoMergeLevel2 : config.stateReconciler; |
||||
return persistReducer(config, combineReducers(reducers)); |
||||
} |
||||
@ -0,0 +1,25 @@ |
||||
// @flow |
||||
|
||||
import { combineReducers } from 'redux' |
||||
import persistReducer from './persistReducer' |
||||
import autoMergeLevel2 from './stateReconciler/autoMergeLevel2' |
||||
|
||||
import type { PersistConfig } from './types' |
||||
|
||||
type Reducers = { |
||||
[key: string]: Function, |
||||
} |
||||
|
||||
type Reducer = (state: Object, action: Object) => Object |
||||
|
||||
// combineReducers + persistReducer with stateReconciler defaulted to autoMergeLevel2 |
||||
export default function persistCombineReducers( |
||||
config: PersistConfig, |
||||
reducers: Reducers |
||||
): Reducer { |
||||
config.stateReconciler = |
||||
config.stateReconciler === undefined |
||||
? autoMergeLevel2 |
||||
: config.stateReconciler |
||||
return persistReducer(config, combineReducers(reducers)) |
||||
} |
||||
@ -0,0 +1,153 @@ |
||||
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(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; } |
||||
|
||||
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; } |
||||
|
||||
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } |
||||
|
||||
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } |
||||
|
||||
import { FLUSH, PAUSE, PERSIST, PURGE, REHYDRATE, DEFAULT_VERSION } from './constants'; |
||||
import autoMergeLevel1 from './stateReconciler/autoMergeLevel1'; |
||||
import createPersistoid from './createPersistoid'; |
||||
import defaultGetStoredState from './getStoredState'; |
||||
import purgeStoredState from './purgeStoredState'; |
||||
var DEFAULT_TIMEOUT = 5000; |
||||
/* |
||||
@TODO add validation / handling for: |
||||
- persisting a reducer which has nested _persist |
||||
- handling actions that fire before reydrate is called |
||||
*/ |
||||
|
||||
export default function persistReducer(config, baseReducer) { |
||||
if (process.env.NODE_ENV !== 'production') { |
||||
if (!config) throw new Error('config is required for persistReducer'); |
||||
if (!config.key) throw new Error('key is required in persistor config'); |
||||
if (!config.storage) throw new Error("redux-persist: config.storage is required. Try using one of the provided storage engines `import storage from 'redux-persist/lib/storage'`"); |
||||
} |
||||
|
||||
var version = config.version !== undefined ? config.version : DEFAULT_VERSION; |
||||
var debug = config.debug || false; |
||||
var stateReconciler = config.stateReconciler === undefined ? autoMergeLevel1 : config.stateReconciler; |
||||
var getStoredState = config.getStoredState || defaultGetStoredState; |
||||
var timeout = config.timeout !== undefined ? config.timeout : DEFAULT_TIMEOUT; |
||||
var _persistoid = null; |
||||
var _purge = false; |
||||
var _paused = true; |
||||
|
||||
var conditionalUpdate = function conditionalUpdate(state) { |
||||
// update the persistoid only if we are rehydrated and not paused
|
||||
state._persist.rehydrated && _persistoid && !_paused && _persistoid.update(state); |
||||
return state; |
||||
}; |
||||
|
||||
return function (state, action) { |
||||
var _ref = state || {}, |
||||
_persist = _ref._persist, |
||||
rest = _objectWithoutProperties(_ref, ["_persist"]); // $FlowIgnore need to update State type
|
||||
|
||||
|
||||
var restState = rest; |
||||
|
||||
if (action.type === PERSIST) { |
||||
var _sealed = false; |
||||
|
||||
var _rehydrate = function _rehydrate(payload, err) { |
||||
// dev warning if we are already sealed
|
||||
if (process.env.NODE_ENV !== 'production' && _sealed) console.error("redux-persist: rehydrate for \"".concat(config.key, "\" called after timeout."), payload, err); // only rehydrate if we are not already sealed
|
||||
|
||||
if (!_sealed) { |
||||
action.rehydrate(config.key, payload, err); |
||||
_sealed = true; |
||||
} |
||||
}; |
||||
|
||||
timeout && setTimeout(function () { |
||||
!_sealed && _rehydrate(undefined, new Error("redux-persist: persist timed out for persist key \"".concat(config.key, "\""))); |
||||
}, timeout); // @NOTE PERSIST resumes if paused.
|
||||
|
||||
_paused = false; // @NOTE only ever create persistoid once, ensure we call it at least once, even if _persist has already been set
|
||||
|
||||
if (!_persistoid) _persistoid = createPersistoid(config); // @NOTE PERSIST can be called multiple times, noop after the first
|
||||
|
||||
if (_persist) { |
||||
// We still need to call the base reducer because there might be nested
|
||||
// uses of persistReducer which need to be aware of the PERSIST action
|
||||
return _objectSpread({}, baseReducer(restState, action), { |
||||
_persist: _persist |
||||
}); |
||||
} |
||||
|
||||
if (typeof action.rehydrate !== 'function' || typeof action.register !== 'function') throw new Error('redux-persist: either rehydrate or register is not a function on the PERSIST action. This can happen if the action is being replayed. This is an unexplored use case, please open an issue and we will figure out a resolution.'); |
||||
action.register(config.key); |
||||
getStoredState(config).then(function (restoredState) { |
||||
var migrate = config.migrate || function (s, v) { |
||||
return Promise.resolve(s); |
||||
}; |
||||
|
||||
migrate(restoredState, version).then(function (migratedState) { |
||||
_rehydrate(migratedState); |
||||
}, function (migrateErr) { |
||||
if (process.env.NODE_ENV !== 'production' && migrateErr) console.error('redux-persist: migration error', migrateErr); |
||||
|
||||
_rehydrate(undefined, migrateErr); |
||||
}); |
||||
}, function (err) { |
||||
_rehydrate(undefined, err); |
||||
}); |
||||
return _objectSpread({}, baseReducer(restState, action), { |
||||
_persist: { |
||||
version: version, |
||||
rehydrated: false |
||||
} |
||||
}); |
||||
} else if (action.type === PURGE) { |
||||
_purge = true; |
||||
action.result(purgeStoredState(config)); |
||||
return _objectSpread({}, baseReducer(restState, action), { |
||||
_persist: _persist |
||||
}); |
||||
} else if (action.type === FLUSH) { |
||||
action.result(_persistoid && _persistoid.flush()); |
||||
return _objectSpread({}, baseReducer(restState, action), { |
||||
_persist: _persist |
||||
}); |
||||
} else if (action.type === PAUSE) { |
||||
_paused = true; |
||||
} else if (action.type === REHYDRATE) { |
||||
// noop on restState if purging
|
||||
if (_purge) return _objectSpread({}, restState, { |
||||
_persist: _objectSpread({}, _persist, { |
||||
rehydrated: true |
||||
}) // @NOTE if key does not match, will continue to default else below
|
||||
|
||||
}); |
||||
|
||||
if (action.key === config.key) { |
||||
var reducedState = baseReducer(restState, action); |
||||
var inboundState = action.payload; // only reconcile state if stateReconciler and inboundState are both defined
|
||||
|
||||
var reconciledRest = stateReconciler !== false && inboundState !== undefined ? stateReconciler(inboundState, state, reducedState, config) : reducedState; |
||||
|
||||
var _newState = _objectSpread({}, reconciledRest, { |
||||
_persist: _objectSpread({}, _persist, { |
||||
rehydrated: true |
||||
}) |
||||
}); |
||||
|
||||
return conditionalUpdate(_newState); |
||||
} |
||||
} // if we have not already handled PERSIST, straight passthrough
|
||||
|
||||
|
||||
if (!_persist) return baseReducer(state, action); // run base reducer:
|
||||
// is state modified ? return original : return updated
|
||||
|
||||
var newState = baseReducer(restState, action); |
||||
if (newState === restState) return state; |
||||
return conditionalUpdate(_objectSpread({}, newState, { |
||||
_persist: _persist |
||||
})); |
||||
}; |
||||
} |
||||
@ -0,0 +1,201 @@ |
||||
// @flow |
||||
import { |
||||
FLUSH, |
||||
PAUSE, |
||||
PERSIST, |
||||
PURGE, |
||||
REHYDRATE, |
||||
DEFAULT_VERSION, |
||||
} from './constants' |
||||
|
||||
import type { |
||||
PersistConfig, |
||||
MigrationManifest, |
||||
PersistState, |
||||
Persistoid, |
||||
} from './types' |
||||
|
||||
import autoMergeLevel1 from './stateReconciler/autoMergeLevel1' |
||||
import createPersistoid from './createPersistoid' |
||||
import defaultGetStoredState from './getStoredState' |
||||
import purgeStoredState from './purgeStoredState' |
||||
|
||||
type PersistPartial = { _persist: PersistState } |
||||
const DEFAULT_TIMEOUT = 5000 |
||||
/* |
||||
@TODO add validation / handling for: |
||||
- persisting a reducer which has nested _persist |
||||
- handling actions that fire before reydrate is called |
||||
*/ |
||||
export default function persistReducer<State: Object, Action: Object>( |
||||
config: PersistConfig, |
||||
baseReducer: (State, Action) => State |
||||
): (State, Action) => State & PersistPartial { |
||||
if (process.env.NODE_ENV !== 'production') { |
||||
if (!config) throw new Error('config is required for persistReducer') |
||||
if (!config.key) throw new Error('key is required in persistor config') |
||||
if (!config.storage) |
||||
throw new Error( |
||||
"redux-persist: config.storage is required. Try using one of the provided storage engines `import storage from 'redux-persist/lib/storage'`" |
||||
) |
||||
} |
||||
|
||||
const version = |
||||
config.version !== undefined ? config.version : DEFAULT_VERSION |
||||
const debug = config.debug || false |
||||
const stateReconciler = |
||||
config.stateReconciler === undefined |
||||
? autoMergeLevel1 |
||||
: config.stateReconciler |
||||
const getStoredState = config.getStoredState || defaultGetStoredState |
||||
const timeout = |
||||
config.timeout !== undefined ? config.timeout : DEFAULT_TIMEOUT |
||||
let _persistoid = null |
||||
let _purge = false |
||||
let _paused = true |
||||
const conditionalUpdate = state => { |
||||
// update the persistoid only if we are rehydrated and not paused |
||||
state._persist.rehydrated && |
||||
_persistoid && |
||||
!_paused && |
||||
_persistoid.update(state) |
||||
return state |
||||
} |
||||
|
||||
return (state: State, action: Action) => { |
||||
let { _persist, ...rest } = state || {} |
||||
// $FlowIgnore need to update State type |
||||
let restState: State = rest |
||||
|
||||
if (action.type === PERSIST) { |
||||
let _sealed = false |
||||
let _rehydrate = (payload, err) => { |
||||
// dev warning if we are already sealed |
||||
if (process.env.NODE_ENV !== 'production' && _sealed) |
||||
console.error( |
||||
`redux-persist: rehydrate for "${ |
||||
config.key |
||||
}" called after timeout.`, |
||||
payload, |
||||
err |
||||
) |
||||
|
||||
// only rehydrate if we are not already sealed |
||||
if (!_sealed) { |
||||
action.rehydrate(config.key, payload, err) |
||||
_sealed = true |
||||
} |
||||
} |
||||
timeout && |
||||
setTimeout(() => { |
||||
!_sealed && |
||||
_rehydrate( |
||||
undefined, |
||||
new Error( |
||||
`redux-persist: persist timed out for persist key "${ |
||||
config.key |
||||
}"` |
||||
) |
||||
) |
||||
}, timeout) |
||||
|
||||
// @NOTE PERSIST resumes if paused. |
||||
_paused = false |
||||
|
||||
// @NOTE only ever create persistoid once, ensure we call it at least once, even if _persist has already been set |
||||
if (!_persistoid) _persistoid = createPersistoid(config) |
||||
|
||||
// @NOTE PERSIST can be called multiple times, noop after the first |
||||
if (_persist) { |
||||
// We still need to call the base reducer because there might be nested |
||||
// uses of persistReducer which need to be aware of the PERSIST action |
||||
return { |
||||
...baseReducer(restState, action), |
||||
_persist, |
||||
}; |
||||
} |
||||
|
||||
if ( |
||||
typeof action.rehydrate !== 'function' || |
||||
typeof action.register !== 'function' |
||||
) |
||||
throw new Error( |
||||
'redux-persist: either rehydrate or register is not a function on the PERSIST action. This can happen if the action is being replayed. This is an unexplored use case, please open an issue and we will figure out a resolution.' |
||||
) |
||||
|
||||
action.register(config.key) |
||||
|
||||
getStoredState(config).then( |
||||
restoredState => { |
||||
const migrate = config.migrate || ((s, v) => Promise.resolve(s)) |
||||
migrate(restoredState, version).then( |
||||
migratedState => { |
||||
_rehydrate(migratedState) |
||||
}, |
||||
migrateErr => { |
||||
if (process.env.NODE_ENV !== 'production' && migrateErr) |
||||
console.error('redux-persist: migration error', migrateErr) |
||||
_rehydrate(undefined, migrateErr) |
||||
} |
||||
) |
||||
}, |
||||
err => { |
||||
_rehydrate(undefined, err) |
||||
} |
||||
) |
||||
|
||||
return { |
||||
...baseReducer(restState, action), |
||||
_persist: { version, rehydrated: false }, |
||||
} |
||||
} else if (action.type === PURGE) { |
||||
_purge = true |
||||
action.result(purgeStoredState(config)) |
||||
return { |
||||
...baseReducer(restState, action), |
||||
_persist, |
||||
} |
||||
} else if (action.type === FLUSH) { |
||||
action.result(_persistoid && _persistoid.flush()) |
||||
return { |
||||
...baseReducer(restState, action), |
||||
_persist, |
||||
} |
||||
} else if (action.type === PAUSE) { |
||||
_paused = true |
||||
} else if (action.type === REHYDRATE) { |
||||
// noop on restState if purging |
||||
if (_purge) |
||||
return { |
||||
...restState, |
||||
_persist: { ..._persist, rehydrated: true }, |
||||
} |
||||
|
||||
// @NOTE if key does not match, will continue to default else below |
||||
if (action.key === config.key) { |
||||
let reducedState = baseReducer(restState, action) |
||||
let inboundState = action.payload |
||||
// only reconcile state if stateReconciler and inboundState are both defined |
||||
let reconciledRest: State = |
||||
stateReconciler !== false && inboundState !== undefined |
||||
? stateReconciler(inboundState, state, reducedState, config) |
||||
: reducedState |
||||
|
||||
let newState = { |
||||
...reconciledRest, |
||||
_persist: { ..._persist, rehydrated: true }, |
||||
} |
||||
return conditionalUpdate(newState) |
||||
} |
||||
} |
||||
|
||||
// if we have not already handled PERSIST, straight passthrough |
||||
if (!_persist) return baseReducer(state, action) |
||||
|
||||
// run base reducer: |
||||
// is state modified ? return original : return updated |
||||
let newState = baseReducer(restState, action) |
||||
if (newState === restState) return state |
||||
return conditionalUpdate({ ...newState, _persist }) |
||||
} |
||||
} |
||||
@ -0,0 +1,127 @@ |
||||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); } |
||||
|
||||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); } |
||||
|
||||
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); } |
||||
|
||||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } } |
||||
|
||||
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(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; } |
||||
|
||||
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; } |
||||
|
||||
import { createStore } from 'redux'; |
||||
import { FLUSH, PAUSE, PERSIST, PURGE, REGISTER, REHYDRATE } from './constants'; |
||||
var initialState = { |
||||
registry: [], |
||||
bootstrapped: false |
||||
}; |
||||
|
||||
var persistorReducer = function persistorReducer() { |
||||
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initialState; |
||||
var action = arguments.length > 1 ? arguments[1] : undefined; |
||||
|
||||
switch (action.type) { |
||||
case REGISTER: |
||||
return _objectSpread({}, state, { |
||||
registry: [].concat(_toConsumableArray(state.registry), [action.key]) |
||||
}); |
||||
|
||||
case REHYDRATE: |
||||
var firstIndex = state.registry.indexOf(action.key); |
||||
|
||||
var registry = _toConsumableArray(state.registry); |
||||
|
||||
registry.splice(firstIndex, 1); |
||||
return _objectSpread({}, state, { |
||||
registry: registry, |
||||
bootstrapped: registry.length === 0 |
||||
}); |
||||
|
||||
default: |
||||
return state; |
||||
} |
||||
}; |
||||
|
||||
export default function persistStore(store, options, cb) { |
||||
// help catch incorrect usage of passing PersistConfig in as PersistorOptions
|
||||
if (process.env.NODE_ENV !== 'production') { |
||||
var optionsToTest = options || {}; |
||||
var bannedKeys = ['blacklist', 'whitelist', 'transforms', 'storage', 'keyPrefix', 'migrate']; |
||||
bannedKeys.forEach(function (k) { |
||||
if (!!optionsToTest[k]) console.error("redux-persist: invalid option passed to persistStore: \"".concat(k, "\". You may be incorrectly passing persistConfig into persistStore, whereas it should be passed into persistReducer.")); |
||||
}); |
||||
} |
||||
|
||||
var boostrappedCb = cb || false; |
||||
|
||||
var _pStore = createStore(persistorReducer, initialState, options && options.enhancer ? options.enhancer : undefined); |
||||
|
||||
var register = function register(key) { |
||||
_pStore.dispatch({ |
||||
type: REGISTER, |
||||
key: key |
||||
}); |
||||
}; |
||||
|
||||
var rehydrate = function rehydrate(key, payload, err) { |
||||
var rehydrateAction = { |
||||
type: REHYDRATE, |
||||
payload: payload, |
||||
err: err, |
||||
key: key // dispatch to `store` to rehydrate and `persistor` to track result
|
||||
|
||||
}; |
||||
store.dispatch(rehydrateAction); |
||||
|
||||
_pStore.dispatch(rehydrateAction); |
||||
|
||||
if (boostrappedCb && persistor.getState().bootstrapped) { |
||||
boostrappedCb(); |
||||
boostrappedCb = false; |
||||
} |
||||
}; |
||||
|
||||
var persistor = _objectSpread({}, _pStore, { |
||||
purge: function purge() { |
||||
var results = []; |
||||
store.dispatch({ |
||||
type: PURGE, |
||||
result: function result(purgeResult) { |
||||
results.push(purgeResult); |
||||
} |
||||
}); |
||||
return Promise.all(results); |
||||
}, |
||||
flush: function flush() { |
||||
var results = []; |
||||
store.dispatch({ |
||||
type: FLUSH, |
||||
result: function result(flushResult) { |
||||
results.push(flushResult); |
||||
} |
||||
}); |
||||
return Promise.all(results); |
||||
}, |
||||
pause: function pause() { |
||||
store.dispatch({ |
||||
type: PAUSE |
||||
}); |
||||
}, |
||||
persist: function persist() { |
||||
store.dispatch({ |
||||
type: PERSIST, |
||||
register: register, |
||||
rehydrate: rehydrate |
||||
}); |
||||
} |
||||
}); |
||||
|
||||
if (!(options && options.manualPersist)) { |
||||
persistor.persist(); |
||||
} |
||||
|
||||
return persistor; |
||||
} |
||||
@ -0,0 +1,130 @@ |
||||
// @flow |
||||
|
||||
import type { |
||||
Persistor, |
||||
PersistConfig, |
||||
PersistorOptions, |
||||
PersistorState, |
||||
MigrationManifest, |
||||
RehydrateAction, |
||||
RehydrateErrorType, |
||||
} from './types' |
||||
|
||||
import { createStore } from 'redux' |
||||
import { FLUSH, PAUSE, PERSIST, PURGE, REGISTER, REHYDRATE } from './constants' |
||||
|
||||
type PendingRehydrate = [Object, RehydrateErrorType, PersistConfig] |
||||
type Persist = <R>(PersistConfig, MigrationManifest) => R => R |
||||
type CreatePersistor = Object => void |
||||
type BoostrappedCb = () => any |
||||
|
||||
const initialState: PersistorState = { |
||||
registry: [], |
||||
bootstrapped: false, |
||||
} |
||||
|
||||
const persistorReducer = (state = initialState, action) => { |
||||
switch (action.type) { |
||||
case REGISTER: |
||||
return { ...state, registry: [...state.registry, action.key] } |
||||
case REHYDRATE: |
||||
let firstIndex = state.registry.indexOf(action.key) |
||||
let registry = [...state.registry] |
||||
registry.splice(firstIndex, 1) |
||||
return { ...state, registry, bootstrapped: registry.length === 0 } |
||||
default: |
||||
return state |
||||
} |
||||
} |
||||
|
||||
export default function persistStore( |
||||
store: Object, |
||||
options?: ?PersistorOptions, |
||||
cb?: BoostrappedCb |
||||
): Persistor { |
||||
// help catch incorrect usage of passing PersistConfig in as PersistorOptions |
||||
if (process.env.NODE_ENV !== 'production') { |
||||
let optionsToTest: Object = options || {} |
||||
let bannedKeys = [ |
||||
'blacklist', |
||||
'whitelist', |
||||
'transforms', |
||||
'storage', |
||||
'keyPrefix', |
||||
'migrate', |
||||
] |
||||
bannedKeys.forEach(k => { |
||||
if (!!optionsToTest[k]) |
||||
console.error( |
||||
`redux-persist: invalid option passed to persistStore: "${k}". You may be incorrectly passing persistConfig into persistStore, whereas it should be passed into persistReducer.` |
||||
) |
||||
}) |
||||
} |
||||
let boostrappedCb = cb || false |
||||
|
||||
let _pStore = createStore( |
||||
persistorReducer, |
||||
initialState, |
||||
options && options.enhancer ? options.enhancer : undefined |
||||
) |
||||
let register = (key: string) => { |
||||
_pStore.dispatch({ |
||||
type: REGISTER, |
||||
key, |
||||
}) |
||||
} |
||||
|
||||
let rehydrate = (key: string, payload: Object, err: any) => { |
||||
let rehydrateAction = { |
||||
type: REHYDRATE, |
||||
payload, |
||||
err, |
||||
key, |
||||
} |
||||
// dispatch to `store` to rehydrate and `persistor` to track result |
||||
store.dispatch(rehydrateAction) |
||||
_pStore.dispatch(rehydrateAction) |
||||
if (boostrappedCb && persistor.getState().bootstrapped) { |
||||
boostrappedCb() |
||||
boostrappedCb = false |
||||
} |
||||
} |
||||
|
||||
let persistor: Persistor = { |
||||
..._pStore, |
||||
purge: () => { |
||||
let results = [] |
||||
store.dispatch({ |
||||
type: PURGE, |
||||
result: purgeResult => { |
||||
results.push(purgeResult) |
||||
}, |
||||
}) |
||||
return Promise.all(results) |
||||
}, |
||||
flush: () => { |
||||
let results = [] |
||||
store.dispatch({ |
||||
type: FLUSH, |
||||
result: flushResult => { |
||||
results.push(flushResult) |
||||
}, |
||||
}) |
||||
return Promise.all(results) |
||||
}, |
||||
pause: () => { |
||||
store.dispatch({ |
||||
type: PAUSE, |
||||
}) |
||||
}, |
||||
persist: () => { |
||||
store.dispatch({ type: PERSIST, register, rehydrate }) |
||||
}, |
||||
} |
||||
|
||||
if (!(options && options.manualPersist)){ |
||||
persistor.persist() |
||||
} |
||||
|
||||
return persistor |
||||
} |
||||
@ -0,0 +1,12 @@ |
||||
import { KEY_PREFIX } from './constants'; |
||||
export default function purgeStoredState(config) { |
||||
var storage = config.storage; |
||||
var storageKey = "".concat(config.keyPrefix !== undefined ? config.keyPrefix : KEY_PREFIX).concat(config.key); |
||||
return storage.removeItem(storageKey, warnIfRemoveError); |
||||
} |
||||
|
||||
function warnIfRemoveError(err) { |
||||
if (err && process.env.NODE_ENV !== 'production') { |
||||
console.error('redux-persist/purgeStoredState: Error purging data stored state', err); |
||||
} |
||||
} |
||||
@ -0,0 +1,22 @@ |
||||
// @flow |
||||
|
||||
import type { PersistConfig } from './types' |
||||
|
||||
import { KEY_PREFIX } from './constants' |
||||
|
||||
export default function purgeStoredState(config: PersistConfig) { |
||||
const storage = config.storage |
||||
const storageKey = `${ |
||||
config.keyPrefix !== undefined ? config.keyPrefix : KEY_PREFIX |
||||
}${config.key}` |
||||
return storage.removeItem(storageKey, warnIfRemoveError) |
||||
} |
||||
|
||||
function warnIfRemoveError(err) { |
||||
if (err && process.env.NODE_ENV !== 'production') { |
||||
console.error( |
||||
'redux-persist/purgeStoredState: Error purging data stored state', |
||||
err |
||||
) |
||||
} |
||||
} |
||||
@ -0,0 +1,37 @@ |
||||
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); } |
||||
|
||||
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(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; } |
||||
|
||||
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; } |
||||
|
||||
/* |
||||
autoMergeLevel1:
|
||||
- merges 1 level of substate |
||||
- skips substate if already modified |
||||
*/ |
||||
export default function autoMergeLevel1(inboundState, originalState, reducedState, _ref) { |
||||
var debug = _ref.debug; |
||||
|
||||
var newState = _objectSpread({}, reducedState); // only rehydrate if inboundState exists and is an object
|
||||
|
||||
|
||||
if (inboundState && _typeof(inboundState) === 'object') { |
||||
Object.keys(inboundState).forEach(function (key) { |
||||
// ignore _persist data
|
||||
if (key === '_persist') return; // if reducer modifies substate, skip auto rehydration
|
||||
|
||||
if (originalState[key] !== reducedState[key]) { |
||||
if (process.env.NODE_ENV !== 'production' && debug) console.log('redux-persist/stateReconciler: sub state for key `%s` modified, skipping.', key); |
||||
return; |
||||
} // otherwise hard set the new value
|
||||
|
||||
|
||||
newState[key] = inboundState[key]; |
||||
}); |
||||
} |
||||
|
||||
if (process.env.NODE_ENV !== 'production' && debug && inboundState && _typeof(inboundState) === 'object') console.log("redux-persist/stateReconciler: rehydrated keys '".concat(Object.keys(inboundState).join(', '), "'")); |
||||
return newState; |
||||
} |
||||
@ -0,0 +1,50 @@ |
||||
// @flow |
||||
|
||||
/* |
||||
autoMergeLevel1: |
||||
- merges 1 level of substate |
||||
- skips substate if already modified |
||||
*/ |
||||
|
||||
import type { PersistConfig } from '../types' |
||||
|
||||
export default function autoMergeLevel1<State: Object>( |
||||
inboundState: State, |
||||
originalState: State, |
||||
reducedState: State, |
||||
{ debug }: PersistConfig |
||||
): State { |
||||
let newState = { ...reducedState } |
||||
// only rehydrate if inboundState exists and is an object |
||||
if (inboundState && typeof inboundState === 'object') { |
||||
Object.keys(inboundState).forEach(key => { |
||||
// ignore _persist data |
||||
if (key === '_persist') return |
||||
// if reducer modifies substate, skip auto rehydration |
||||
if (originalState[key] !== reducedState[key]) { |
||||
if (process.env.NODE_ENV !== 'production' && debug) |
||||
console.log( |
||||
'redux-persist/stateReconciler: sub state for key `%s` modified, skipping.', |
||||
key |
||||
) |
||||
return |
||||
} |
||||
// otherwise hard set the new value |
||||
newState[key] = inboundState[key] |
||||
}) |
||||
} |
||||
|
||||
if ( |
||||
process.env.NODE_ENV !== 'production' && |
||||
debug && |
||||
inboundState && |
||||
typeof inboundState === 'object' |
||||
) |
||||
console.log( |
||||
`redux-persist/stateReconciler: rehydrated keys '${Object.keys( |
||||
inboundState |
||||
).join(', ')}'` |
||||
) |
||||
|
||||
return newState |
||||
} |
||||
@ -0,0 +1,48 @@ |
||||
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); } |
||||
|
||||
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(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; } |
||||
|
||||
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; } |
||||
|
||||
/* |
||||
autoMergeLevel2:
|
||||
- merges 2 level of substate |
||||
- skips substate if already modified |
||||
- this is essentially redux-perist v4 behavior |
||||
*/ |
||||
export default function autoMergeLevel2(inboundState, originalState, reducedState, _ref) { |
||||
var debug = _ref.debug; |
||||
|
||||
var newState = _objectSpread({}, reducedState); // only rehydrate if inboundState exists and is an object
|
||||
|
||||
|
||||
if (inboundState && _typeof(inboundState) === 'object') { |
||||
Object.keys(inboundState).forEach(function (key) { |
||||
// ignore _persist data
|
||||
if (key === '_persist') return; // if reducer modifies substate, skip auto rehydration
|
||||
|
||||
if (originalState[key] !== reducedState[key]) { |
||||
if (process.env.NODE_ENV !== 'production' && debug) console.log('redux-persist/stateReconciler: sub state for key `%s` modified, skipping.', key); |
||||
return; |
||||
} |
||||
|
||||
if (isPlainEnoughObject(reducedState[key])) { |
||||
// if object is plain enough shallow merge the new values (hence "Level2")
|
||||
newState[key] = _objectSpread({}, newState[key], {}, inboundState[key]); |
||||
return; |
||||
} // otherwise hard set
|
||||
|
||||
|
||||
newState[key] = inboundState[key]; |
||||
}); |
||||
} |
||||
|
||||
if (process.env.NODE_ENV !== 'production' && debug && inboundState && _typeof(inboundState) === 'object') console.log("redux-persist/stateReconciler: rehydrated keys '".concat(Object.keys(inboundState).join(', '), "'")); |
||||
return newState; |
||||
} |
||||
|
||||
function isPlainEnoughObject(o) { |
||||
return o !== null && !Array.isArray(o) && _typeof(o) === 'object'; |
||||
} |
||||
@ -0,0 +1,60 @@ |
||||
// @flow |
||||
|
||||
/* |
||||
autoMergeLevel2: |
||||
- merges 2 level of substate |
||||
- skips substate if already modified |
||||
- this is essentially redux-perist v4 behavior |
||||
*/ |
||||
|
||||
import type { PersistConfig } from '../types' |
||||
|
||||
export default function autoMergeLevel2<State: Object>( |
||||
inboundState: State, |
||||
originalState: State, |
||||
reducedState: State, |
||||
{ debug }: PersistConfig |
||||
): State { |
||||
let newState = { ...reducedState } |
||||
// only rehydrate if inboundState exists and is an object |
||||
if (inboundState && typeof inboundState === 'object') { |
||||
Object.keys(inboundState).forEach(key => { |
||||
// ignore _persist data |
||||
if (key === '_persist') return |
||||
// if reducer modifies substate, skip auto rehydration |
||||
if (originalState[key] !== reducedState[key]) { |
||||
if (process.env.NODE_ENV !== 'production' && debug) |
||||
console.log( |
||||
'redux-persist/stateReconciler: sub state for key `%s` modified, skipping.', |
||||
key |
||||
) |
||||
return |
||||
} |
||||
if (isPlainEnoughObject(reducedState[key])) { |
||||
// if object is plain enough shallow merge the new values (hence "Level2") |
||||
newState[key] = { ...newState[key], ...inboundState[key] } |
||||
return |
||||
} |
||||
// otherwise hard set |
||||
newState[key] = inboundState[key] |
||||
}) |
||||
} |
||||
|
||||
if ( |
||||
process.env.NODE_ENV !== 'production' && |
||||
debug && |
||||
inboundState && |
||||
typeof inboundState === 'object' |
||||
) |
||||
console.log( |
||||
`redux-persist/stateReconciler: rehydrated keys '${Object.keys( |
||||
inboundState |
||||
).join(', ')}'` |
||||
) |
||||
|
||||
return newState |
||||
} |
||||
|
||||
function isPlainEnoughObject(o) { |
||||
return o !== null && !Array.isArray(o) && typeof o === 'object' |
||||
} |
||||
@ -0,0 +1,7 @@ |
||||
/* |
||||
hardSet:
|
||||
- hard set incoming state |
||||
*/ |
||||
export default function hardSet(inboundState) { |
||||
return inboundState; |
||||
} |
||||
@ -0,0 +1,10 @@ |
||||
// @flow |
||||
|
||||
/* |
||||
hardSet: |
||||
- hard set incoming state |
||||
*/ |
||||
|
||||
export default function hardSet<State: Object>(inboundState: State): State { |
||||
return inboundState |
||||
} |
||||
@ -0,0 +1,21 @@ |
||||
import getStorage from './getStorage'; |
||||
export default function createWebStorage(type) { |
||||
var storage = getStorage(type); |
||||
return { |
||||
getItem: function getItem(key) { |
||||
return new Promise(function (resolve, reject) { |
||||
resolve(storage.getItem(key)); |
||||
}); |
||||
}, |
||||
setItem: function setItem(key, item) { |
||||
return new Promise(function (resolve, reject) { |
||||
resolve(storage.setItem(key, item)); |
||||
}); |
||||
}, |
||||
removeItem: function removeItem(key) { |
||||
return new Promise(function (resolve, reject) { |
||||
resolve(storage.removeItem(key)); |
||||
}); |
||||
} |
||||
}; |
||||
} |
||||
@ -0,0 +1,23 @@ |
||||
// @flow |
||||
import getStorage from './getStorage' |
||||
|
||||
export default function createWebStorage(type: string) { |
||||
let storage = getStorage(type) |
||||
return { |
||||
getItem: (key: string): Promise<string> => { |
||||
return new Promise((resolve, reject) => { |
||||
resolve(storage.getItem(key)) |
||||
}) |
||||
}, |
||||
setItem: (key: string, item: string): Promise<void> => { |
||||
return new Promise((resolve, reject) => { |
||||
resolve(storage.setItem(key, item)) |
||||
}) |
||||
}, |
||||
removeItem: (key: string): Promise<void> => { |
||||
return new Promise((resolve, reject) => { |
||||
resolve(storage.removeItem(key)) |
||||
}) |
||||
}, |
||||
} |
||||
} |
||||
@ -0,0 +1,39 @@ |
||||
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); } |
||||
|
||||
function noop() {} |
||||
|
||||
var noopStorage = { |
||||
getItem: noop, |
||||
setItem: noop, |
||||
removeItem: noop |
||||
}; |
||||
|
||||
function hasStorage(storageType) { |
||||
if ((typeof self === "undefined" ? "undefined" : _typeof(self)) !== 'object' || !(storageType in self)) { |
||||
return false; |
||||
} |
||||
|
||||
try { |
||||
var storage = self[storageType]; |
||||
var testKey = "redux-persist ".concat(storageType, " test"); |
||||
storage.setItem(testKey, 'test'); |
||||
storage.getItem(testKey); |
||||
storage.removeItem(testKey); |
||||
} catch (e) { |
||||
if (process.env.NODE_ENV !== 'production') console.warn("redux-persist ".concat(storageType, " test failed, persistence will be disabled.")); |
||||
return false; |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
||||
export default function getStorage(type) { |
||||
var storageType = "".concat(type, "Storage"); |
||||
if (hasStorage(storageType)) return self[storageType];else { |
||||
if (process.env.NODE_ENV !== 'production') { |
||||
console.error("redux-persist failed to create sync storage. falling back to noop storage."); |
||||
} |
||||
|
||||
return noopStorage; |
||||
} |
||||
} |
||||
@ -0,0 +1,44 @@ |
||||
// @flow |
||||
|
||||
import type { Storage } from '../types' |
||||
|
||||
function noop() {} |
||||
let noopStorage = { |
||||
getItem: noop, |
||||
setItem: noop, |
||||
removeItem: noop, |
||||
} |
||||
|
||||
function hasStorage(storageType) { |
||||
if (typeof self !== 'object' || !(storageType in self)) { |
||||
return false |
||||
} |
||||
|
||||
try { |
||||
let storage = self[storageType] |
||||
const testKey = `redux-persist ${storageType} test` |
||||
storage.setItem(testKey, 'test') |
||||
storage.getItem(testKey) |
||||
storage.removeItem(testKey) |
||||
} catch (e) { |
||||
if (process.env.NODE_ENV !== 'production') |
||||
console.warn( |
||||
`redux-persist ${storageType} test failed, persistence will be disabled.` |
||||
) |
||||
return false |
||||
} |
||||
return true |
||||
} |
||||
|
||||
export default function getStorage(type: string): Storage { |
||||
const storageType = `${type}Storage` |
||||
if (hasStorage(storageType)) return self[storageType] |
||||
else { |
||||
if (process.env.NODE_ENV !== 'production') { |
||||
console.error( |
||||
`redux-persist failed to create sync storage. falling back to noop storage.` |
||||
) |
||||
} |
||||
return noopStorage |
||||
} |
||||
} |
||||
@ -0,0 +1,2 @@ |
||||
import createWebStorage from './createWebStorage'; |
||||
export default createWebStorage('local'); |
||||
@ -0,0 +1,5 @@ |
||||
// @flow |
||||
|
||||
import createWebStorage from './createWebStorage' |
||||
|
||||
export default createWebStorage('local') |
||||
@ -0,0 +1,2 @@ |
||||
import createWebStorage from './createWebStorage'; |
||||
export default createWebStorage('session'); |
||||
@ -0,0 +1,5 @@ |
||||
// @flow |
||||
|
||||
import createWebStorage from './createWebStorage' |
||||
|
||||
export default createWebStorage('session') |
||||
@ -0,0 +1 @@ |
||||
import { REHYDRATE, REGISTER } from './constants'; |
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue