You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
74 KiB

2 years ago
{"version":3,"file":"redux-persist.js","sources":["../src/constants.js","../src/stateReconciler/autoMergeLevel1.js","../src/createPersistoid.js","../src/getStoredState.js","../src/purgeStoredState.js","../src/persistReducer.js","../node_modules/symbol-observable/es/ponyfill.js","../node_modules/symbol-observable/es/index.js","../node_modules/redux/es/redux.js","../src/stateReconciler/autoMergeLevel2.js","../src/persistCombineReducers.js","../src/persistStore.js","../src/createMigrate.js","../src/createTransform.js"],"sourcesContent":["// @flow\n\nexport const KEY_PREFIX = 'persist:'\nexport const FLUSH = 'persist/FLUSH'\nexport const REHYDRATE = 'persist/REHYDRATE'\nexport const PAUSE = 'persist/PAUSE'\nexport const PERSIST = 'persist/PERSIST'\nexport const PURGE = 'persist/PURGE'\nexport const REGISTER = 'persist/REGISTER'\nexport const DEFAULT_VERSION = -1\n","// @flow\n\n/*\n autoMergeLevel1: \n - merges 1 level of substate\n - skips substate if already modified\n*/\n\nimport type { PersistConfig } from '../types'\n\nexport default function autoMergeLevel1<State: Object>(\n inboundState: State,\n originalState: State,\n reducedState: State,\n { debug }: PersistConfig\n): State {\n let newState = { ...reducedState }\n // only rehydrate if inboundState exists and is an object\n if (inboundState && typeof inboundState === 'object') {\n Object.keys(inboundState).forEach(key => {\n // ignore _persist data\n if (key === '_persist') return\n // if reducer modifies substate, skip auto rehydration\n if (originalState[key] !== reducedState[key]) {\n if (process.env.NODE_ENV !== 'production' && debug)\n console.log(\n 'redux-persist/stateReconciler: sub state for key `%s` modified, skipping.',\n key\n )\n return\n }\n // otherwise hard set the new value\n newState[key] = inboundState[key]\n })\n }\n\n if (\n process.env.NODE_ENV !== 'production' &&\n debug &&\n inboundState &&\n typeof inboundState === 'object'\n )\n console.log(\n `redux-persist/stateReconciler: rehydrated keys '${Object.keys(\n inboundState\n ).join(', ')}'`\n )\n\n return newState\n}\n","// @flow\n\nimport { KEY_PREFIX, REHYDRATE } from './constants'\n\nimport type { Persistoid, PersistConfig, Transform } from './types'\n\ntype IntervalID = any // @TODO remove once flow < 0.63 support is no longer required.\n\nexport default function createPersistoid(config: PersistConfig): Persistoid {\n // defaults\n const blacklist: ?Array<string> = config.blacklist || null\n const whitelist: ?Array<string> = config.whitelist || null\n const transforms = config.transforms || []\n const throttle = config.throttle || 0\n const storageKey = `${\n config.keyPrefix !== undefined ? config.keyPrefix : KEY_PREFIX\n }${config.key}`\n const storage = config.storage\n let serialize\n if (config.serialize === false) {\n serialize = x => x\n } else if (typeof config.serialize === 'function') {\n serialize = config.serialize\n } else {\n serialize = defaultSerialize\n }\n const writeFailHandler = config.writeFailHandler || null\n\n // initialize stateful values\n let lastState = {}\n let stagedState = {}\n let keysToProcess = []\n let timeIterator: ?IntervalID = null\n let writePromise = null\n\n const update = (state: Object) => {\n // add any changed keys to the queue\n Object.keys(state).forEach(key => {\n if (!passWhitelistBlacklist(key)) return // is keyspace ignored? noop\n if (lastState[key] === state[key]) return // value unchanged? noop\n if (keysToProcess.indexOf(key) !== -1) return // is key already queued? noop\n keysToProcess.push(key) // add key to queue\n })\n\n //if any key is missing in the new state which was present in the lastState,\n //add it for processing too\n Object.keys(lastState).forEach(key => {\n if (\n state[key] === undefined &&\n passWhitelistBlacklist(key) &&\n keysToProcess.indexOf(key) === -1 &&\n lastSt