diff --git a/README.md b/README.md index 124c764a5..0fb1db356 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,6 @@ 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) -Redux Persist takes your redux state object and saves it to persisted storage. On app launch, it retrieves this persisted state and saves it back to redux. - -**Note:** These instructions are for redux-persist v5. For a list of breaking changes between v4 and v5, see our [migration guide](./docs/MigrationGuide-v5.md). -[v4](https://github.com/rt2zz/redux-persist/tree/v4) will be supported for the forseeable future, and if it works well for your use case you are encouraged to stay on v4. - ## Quickstart `npm install redux-persist` @@ -26,13 +21,13 @@ Basic usage involves adding `persistReducer` and `persistStore` to your setup. * import { createStore } from 'redux' import { persistStore, persistReducer } from 'redux-persist' -import storage from 'redux-persist/lib/storage' +import storage from 'redux-persist/lib/storage' // defaults to localStorage for web and AsyncStorage for react-native import rootReducer from './reducers' const persistConfig = { key: 'root', - storage: storage, + storage, } const persistedReducer = persistReducer(persistConfig, rootReducer) @@ -47,15 +42,9 @@ export default () => { 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 React from 'react' -import { Provider } from 'react-redux' -import { PersistGate } from 'redux-persist/lib/integration/react' - -import configureStore from './store/configureStore' -let { store, persistor } = configureStore() +import { PersistGate } from 'redux-persist/integration/react' -// import your necessary custom components. -import { RootComponent } from './components' +// ... normal setup, create store and persistor, import components etc. const App = () => { return ( @@ -66,8 +55,6 @@ const App = () => { </Provider> ); }; - -export default App ``` ## API @@ -91,13 +78,13 @@ export default App #### `persistor object` - the persistor object is returned by persistStore with the following methods: - - `.purge(keys)` + - `.purge()` - purges state from disk and returns a promise - - `flush()` + - `.flush()` - immediately writes all pending state to disk and returns a promise - - `pause()` + - `.pause()` - pauses persistence - - `persist()` + - `.persist()` - resumes persistence ## State Reconciler @@ -113,7 +100,7 @@ This will auto merge one level deep. Auto merge means if the some piece of subst - **INCOMING STATE**: `{ foo: incomingFoo }` - **INITIAL STATE**: `{ foo: initialFoo, bar: initialBar }` - **RECONCILED STATE**: `{ foo: incomingFoo, bar: initialBar }` -3. autoMergeLevel2 +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 }` @@ -222,8 +209,8 @@ The createTransform function takes three parameters. ## Storage Engines - **localStorage** `import storage from 'redux-persist/lib/storage'` -- **sessionStorage** `import sessionStorage from 'redux-persist/lib/storage/session'` -- **AsyncStorage** react-native `import storage from 'redux-persist/lib/storage'` +- **sessionStorage** `import storageSession from 'redux-persist/lib/storage/session'` +- **AsyncStorage** react-native `import { AsyncStorage } from 'react-native'` - **[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)) diff --git a/integration/README.md b/integration/README.md new file mode 100644 index 000000000..81fed611a --- /dev/null +++ b/integration/README.md @@ -0,0 +1,4 @@ +Proxy package to enable +```js +import { PersistGate } from 'redux-persist/integration/react' +``` \ No newline at end of file diff --git a/integration/react/package.json b/integration/react/package.json new file mode 100644 index 000000000..460f9fc0a --- /dev/null +++ b/integration/react/package.json @@ -0,0 +1,7 @@ +{ + "name": "redux-persist/integration/react", + "private": true, + "main": "../../lib/integration/react", + "module": "../../es/integration/react", + "jsnext:main": "../../es/integration/react" + } \ No newline at end of file diff --git a/package.json b/package.json index 2060a0e15..baa8b90f1 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ }, "lint-staged": { "src/**/*.js": [ - "prettier --no-semi --single-quote --trailing-comma --parser=flow --write", + "prettier --write", "git add" ] }, diff --git a/src/utils/curry.js b/src/utils/curry.js deleted file mode 100644 index b55b1a854..000000000 --- a/src/utils/curry.js +++ /dev/null @@ -1,28 +0,0 @@ -// // @flow -// // credit @gcanti, taken from https://github.com/gcanti/flow-static-land/blob/e36cd55b8f8541e81828ec39964bdb6f5ccbec91/src/Fun.js - -// export type Fn1<A, B> = (a: A, ...rest: Array<void>) => B -// export type Fn2<A, B, C> = (a: A, b: B, ...rest: Array<void>) => C -// export type Fn3<A, B, C, D> = (a: A, b: B, c: C, ...rest: Array<void>) => D - -// export type CurriedFn2<A, B, C> = Fn1<A, Fn1<B, C>> & Fn2<A, B, C> -// export type CurriedFn3<A, B, C, D> = Fn1<A, CurriedFn2<B, C, D>> & -// Fn2<A, B, Fn1<C, D>> & -// Fn3<A, B, C, D> - -// declare function curry<A, B, C>(f: Fn2<A, B, C>): CurriedFn2<A, B, C> // eslint-disable-line no-redeclare -// declare function curry<A, B, C, D>(f: Fn3<A, B, C, D>): CurriedFn3<A, B, C, D> // eslint-disable-line no-redeclare - -// declare function curried(f, length, acc) { -// return function() { -// const combined = acc.concat(Array.prototype.slice.call(arguments)) -// return combined.length >= length -// ? f.apply(this, combined) -// : curried(f, length, combined) -// } -// } - -// export function curry(f: Function) { -// // eslint-disable-line no-redeclare -// return curried(f, f.length, []) -// }