{"_id":"@charliehess/redux-persist","_rev":"2-aec1748b02abe2ac095f818270137c90","name":"@charliehess/redux-persist","description":"persist and rehydrate redux stores","dist-tags":{"latest":"4.9.0"},"versions":{"4.9.0":{"name":"@charliehess/redux-persist","version":"4.9.0","description":"persist and rehydrate redux stores","main":"lib/index.js","typings":"lib/index.d.ts","module":"es/index.js","jsnext:main":"es/index.js","scripts":{"test":"standard 'src/**/*.js' 'test/**/*.js' && BABEL_ENV=commonjs ava --esnext","test:watch":"npm test -- --watch","copy-types":"cp -r type-definitions/ lib/ && cp -r type-definitions/ es/","clean":"rimraf lib dist es","build":"npm run build:commonjs && npm run build:es && npm run build:umd && npm run build:umd:min && npm run copy-types","build:commonjs":"cross-env BABEL_ENV=commonjs babel src --out-dir lib","build:es":"cross-env BABEL_ENV=es babel src --out-dir es","build:umd":"cross-env BABEL_ENV=es NODE_ENV=development rollup -c -i src/index.js -o dist/redux-persist.js","build:umd:min":"cross-env BABEL_ENV=es NODE_ENV=production rollup -c -i src/index.js -o dist/redux-persist.min.js","build:watch":"npm run build:commonjs -- -watch","prepublish":"npm run clean && npm run build"},"ava":{"require":["babel-register","babel-polyfill"],"babel":"inherit"},"repository":{"type":"git","url":"git+https://github.com/CharlieHess/redux-persist.git"},"homepage":"https://github.com/CharlieHess/redux-persist","keywords":["redux","redux-middleware","localstorage","redux-persist","redux-storage","redux-rehydrate"],"author":{"name":"rt2zz","email":"zack@root-two.com"},"license":"MIT","dependencies":{"json-stringify-safe":"^5.0.1","lodash":"^4.17.4","lodash-es":"^4.17.4"},"devDependencies":{"ava":"^0.18.1","babel-cli":"^6.22.2","babel-core":"^6.22.1","babel-eslint":"^7.1.1","babel-plugin-external-helpers":"^6.22.0","babel-polyfill":"^6.22.0","babel-preset-es2015":"^6.22.0","babel-preset-stage-2":"^6.22.0","cross-env":"^3.1.4","immutable":"^3.8.1","redux":"^3.6.0","rimraf":"~2.5.4","rollup":"^0.41.6","rollup-plugin-babel":"^2.7.1","rollup-plugin-commonjs":"^8.0.2","rollup-plugin-node-resolve":"^3.0.0","rollup-plugin-replace":"^1.1.1","rollup-plugin-uglify":"^1.0.2","standard":"^8.6.0"},"files":["es","dist","lib","src","constants","storages","index.js.flow","index.d.ts"],"standard":{"parser":"babel-eslint"},"gitHead":"e72b6672a4a103296d63373b4dca4c12dfea670c","bugs":{"url":"https://github.com/CharlieHess/redux-persist/issues"},"_id":"@charliehess/redux-persist@4.9.0","_shasum":"876987ad8362132b4513305650e4c96ae28bede4","_from":".","_npmVersion":"4.5.0","_nodeVersion":"7.2.0","_npmUser":{"name":"charliehess","email":"ifightnoman@gmail.com"},"dist":{"shasum":"876987ad8362132b4513305650e4c96ae28bede4","tarball":"https://registry.npmjs.org/@charliehess/redux-persist/-/redux-persist-4.9.0.tgz","integrity":"sha512-S7Zq5WrnPCTNexPRfgx7NByVBlmhwn12GPeh+PKkhxHHT5p7hw5G4Ze7ehjf3t7ctIXXxnqp6DGjQBzkwXxrog==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCP+tPDbvSUWElRvKLVCBbDmzt6rTBB451IIrvdsMEefQIgdzG8/3SXwwX+TDiJnLYVdrl35dQtfUlSJet/w4l17iw="}]},"maintainers":[{"name":"charliehess","email":"ifightnoman@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/redux-persist-4.9.0.tgz_1496101218405_0.3550722661893815"}}},"readme":"# Redux Persist\nPersist and rehydrate a redux store.\n\nRedux Persist is [performant](#why-redux-persist), easy to [implement](#basic-usage), and easy to [extend](./docs/ecosystem.md).\n\n`npm i --save redux-persist`\n\n[![build status](https://img.shields.io/travis/rt2zz/redux-persist/master.svg?style=flat-square)](https://travis-ci.org/rt2zz/redux-persist)\n[![npm version](https://img.shields.io/npm/v/redux-persist.svg?style=flat-square)](https://www.npmjs.com/package/redux-persist)\n[![npm downloads](https://img.shields.io/npm/dm/redux-persist.svg?style=flat-square)](https://www.npmjs.com/package/redux-persist)\n\n## Basic Usage\nBasic usage requires adding a few lines to a traditional redux application:\n```js\nimport {compose, applyMiddleware, createStore} from 'redux'\nimport {persistStore, autoRehydrate} from 'redux-persist'\n\n// add `autoRehydrate` as an enhancer to your store (note: `autoRehydrate` is not a middleware)\nconst store = createStore(\n  reducer,\n  undefined,\n  compose(\n    applyMiddleware(...),\n    autoRehydrate()\n  )\n)\n\n// begin periodically persisting the store\npersistStore(store)\n```\nFor per reducer rehydration logic, you can opt-in by adding a handler to your reducer:\n```js\nimport {REHYDRATE} from 'redux-persist/constants'\n//...\ncase REHYDRATE:\n  var incoming = action.payload.myReducer\n  if (incoming) return {...state, ...incoming, specialKey: processSpecial(incoming.specialKey)}\n  return state\n```\nYou may also need to configure the persistence layer, or take action after rehydration has completed:\n```js\npersistStore(store, {blacklist: ['someTransientReducer']}, () => {\n  console.log('rehydration complete')\n})\n```\nAnd if things get out of wack, just purge the storage\n```js\npersistStore(store, config, callback).purge()\n```\n\n## API\n[Full API](./docs/api.md)\n#### `persistStore(store, [config, callback])`\n  - arguments\n    - **store** *redux store* The store to be persisted.\n    - **config** *object*\n      - **blacklist** *array* keys (read: reducers) to ignore\n      - **whitelist** *array* keys (read: reducers) to persist, if set all other keys will be ignored.\n      - **storage** *object* a [conforming](https://github.com/rt2zz/redux-persist#storage-engines) storage engine.\n      - **transforms** *array* transforms to be applied during storage and during rehydration.\n      - **asyncTransforms** *boolean* set to true to allow for asynchronous transforms.\n      - **debounce** *integer* debounce interval applied to storage calls (in miliseconds).\n      - **keyPrefix** *string* change localstorage default key (default: **reduxPersist:**) [Discussion on why we need this feature ?](https://github.com/rt2zz/redux-persist/issues/137)\n    - **callback** *function* will be called after rehydration is finished.\n  - returns **persistor** object\n\n#### `persistor object`\n  - the persistor object is returned by persistStore with the following methods:\n    - `.purge(keys)`\n      - **keys** *array* An array of keys to be purged from storage. If not provided all keys will be purged.\n    - `.rehydrate(incoming, options)`\n      - **incoming** *object* Data to be rehydrated into the store.\n      - **options** *object* If `serial:true`, incoming should be a *string*, that will be deserialized and passed through the transforms defined in the persistor.\n      - Manually rehydrates the store with the passed data, dispatching the rehydrate action.\n    - `pause()`\n      - pauses persistence\n    - `resume()`\n      - resumes persistence\n\n#### `autoRehydrate(config)`\n  - This is a store enhancer that will automatically shallow merge the persisted state for each key. Additionally it queues any actions that are dispatched before rehydration is complete, and fires them after rehydration is finished.\n  - arguments\n    - **config** *object*\n      - **log** *boolean* Turn on debug mode. Default: *false*.\n      - **stateReconciler** *function* override the default shallow merge state reconciliation.\n\n#### `constants`\n  - `import * as constants from 'redux-persist/constants'`. This includes `REHYDRATE` and `KEY_PREFIX`.\n\n## Alternate Usage\n#### getStoredState / createPersistor\nIf you need more control over persistence flow, you can implement `getStoredState` and `createPersistor`. For example you can skip autoRehydrate and directly pass restoredState into your store as initialState:\n\n```js\nimport {getStoredState, autoRehydrate, createPersistor} from 'redux-persist'\n\nconst persistConfig = { /* ... */ }\n\ngetStoredState(persistConfig, (err, restoredState) => {\n  const store = createStore(reducer, restoredState)\n  const persistor = createPersistor(store, persistConfig)\n})\n```\n\n#### Secondary Persistor\n```js\nimport {persistStore, createPersistor} from 'redux-persist'\nconst persistor = persistStore(store) // persistStore restores and persists\nconst secondaryPersistor = createPersistor(store, {storage: specialBackupStorage}) // createPersistor only persists\n```\n\n## Storage Engines\n- **localStorage** (default) web\n- **sessionStorage**\n- **[localForage](https://github.com/mozilla/localForage)** (recommended) web, see usage below\n- **[AsyncStorage](http://facebook.github.io/react-native/docs/asyncstorage.html#content)** for react-native\n- **[redux-persist-node-storage](https://github.com/pellejacobs/redux-persist-node-storage)** for use in nodejs environments.\n- **custom** any conforming storage api implementing the following methods: `setItem` `getItem` `removeItem` `getAllKeys`. [[example](https://github.com/facebook/react-native/blob/master/Libraries/Storage/AsyncStorage.js)]\n\n```js\n// sessionStorage\nimport { persistStore } from 'redux-persist'\nimport { asyncSessionStorage } from 'redux-persist/storages'\npersistStore(store, {storage: asyncSessionStorage})\n\n// react-native\nimport {AsyncStorage} from 'react-native'\npersistStore(store, {storage: AsyncStorage})\n\n// web with recommended localForage\nimport localForage from 'localforage'\npersistStore(store, {storage: localForage})\n\n```\n\n## Transforms\nTransforms allow for arbitrary state transforms before saving and during rehydration.\n- [immutable](https://github.com/rt2zz/redux-persist-transform-immutable) - support immutable reducers\n- [compress](https://github.com/rt2zz/redux-persist-transform-compress) - compress your serialized state with lz-string\n- [encrypt](https://github.com/maxdeviant/redux-persist-transform-encrypt) - encrypt your serialized state with AES\n- [filter](https://github.com/edy/redux-persist-transform-filter) - store or load a subset of your state\n- [filter-immutable](https://github.com/actra-development/redux-persist-transform-filter-immutable) - store or load a subset of your state with support for immutablejs\n- [expire](https://github.com/gabceb/redux-persist-transform-expire) - expire a specific subset of your state based on a property\n- custom transforms:\n```js\nimport { createTransform, persistStore } from 'redux-persist'\n\nlet myTransform = createTransform(\n  // transform state coming from redux on its way to being serialized and stored\n  (inboundState, key) => specialSerialize(inboundState, key),\n  // transform state coming from storage, on its way to be rehydrated into redux\n  (outboundState, key) => specialDeserialize(outboundState, key),\n  // configuration options\n  {whitelist: ['specialReducer']}\n)\n\npersistStore(store, {transforms: [myTransform]})\n```\n- async transforms:\n``` js\nimport { createTransform, persistStore } from 'redux-persist'\n\nlet myTransform = createTransform(\n  async (inboundState, key) => {\n    const serialized = await asyncSerialize(inboundState, key)\n    return serialized\n  },\n  async (outboundState, key) => {\n    const deserialized = await specialDeserialize(outboundState, key)\n    return deserialized\n  },\n  {whitelist: ['specialReducer']}\n)\n\npersistStore(store, {\n  transforms: [myTransform],\n  asyncTransforms: true\n})\n```\n\n## Migrations\nOne challenge developers encounter when persisting state for the first time is what happens when the shape of the application state changes between deployments? Solution: [redux-persist-migrate](https://github.com/wildlifela/redux-persist-migrate)\n\n## Action Buffer\nA common mistake is to fire actions that modify state before rehydration is complete which then will be overwritten by the rehydrate action. You can either defer firing of those actions until rehydration is complete, or you can use an [action buffer](https://github.com/rt2zz/redux-action-buffer/blob/master/README.md#redux-persist-example).\n\n## Why Redux Persist\n\n* Performant out of the box (uses a time iterator and operates on state partials)\n* Keeps custom rehydration logic in the reducers (where it intuitively belongs)\n* Supports localStorage, react-native AsyncStorage, or any conforming storage api\n\nBecause persisting state is inherently stateful, `persistStore` lives outside of the redux store. Importantly this keeps the store 'pure' and makes testing and extending the persistor much easier.\n\n## About Auto Rehydrate\nautoRehydrate is a store enhancer that automatically rehydrates state.\n\nWhile auto rehydration works out of the box, individual reducers can opt in to handling their own rehydration, allowing for more complex operations like data transforms and cache invalidation. Simply define a handler for the rehydrate action in your reducer, and if the state is mutated, auto rehydrate will skip that key.\n\nAuto rehydrate is provided as a convenience. In a large application, or one with atypical reducer composition, auto rehydration may not be convenient. In this case, simply omit autoRehydrate. Rehydration actions will still be fired by `persistStore`, and can then be handled individually by reducers or using a custom rehydration handler.\n","maintainers":[{"name":"charliehess","email":"ifightnoman@gmail.com"}],"time":{"modified":"2022-06-12T15:48:34.031Z","created":"2017-05-29T23:40:18.510Z","4.9.0":"2017-05-29T23:40:18.510Z"},"homepage":"https://github.com/CharlieHess/redux-persist","keywords":["redux","redux-middleware","localstorage","redux-persist","redux-storage","redux-rehydrate"],"repository":{"type":"git","url":"git+https://github.com/CharlieHess/redux-persist.git"},"author":{"name":"rt2zz","email":"zack@root-two.com"},"bugs":{"url":"https://github.com/CharlieHess/redux-persist/issues"},"license":"MIT","readmeFilename":"README.md"}