Skip to content

Commit f8f65dc

Browse files
author
Zack Story
committed
(api): proxy modules, some cleanup (#703)
* (api): proxy modules, some cleanup * Update README.md
1 parent a40e4a5 commit f8f65dc

File tree

5 files changed

+39
-70
lines changed

5 files changed

+39
-70
lines changed

README.md

Lines changed: 27 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ Persist and rehydrate a redux store.
44

55
[![build status](https://img.shields.io/travis/rt2zz/redux-persist/master.svg?style=flat-square)](https://travis-ci.org/rt2zz/redux-persist) [![npm version](https://img.shields.io/npm/v/redux-persist.svg?style=flat-square)](https://www.npmjs.com/package/redux-persist) [![npm downloads](https://img.shields.io/npm/dm/redux-persist.svg?style=flat-square)](https://www.npmjs.com/package/redux-persist)
66

7-
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.
8-
9-
**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).
10-
[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.
11-
127
## Quickstart
138
`npm install redux-persist`
149

@@ -26,13 +21,13 @@ Basic usage involves adding `persistReducer` and `persistStore` to your setup. *
2621

2722
import { createStore } from 'redux'
2823
import { persistStore, persistReducer } from 'redux-persist'
29-
import storage from 'redux-persist/lib/storage'
24+
import storage from 'redux-persist/lib/storage' // defaults to localStorage for web and AsyncStorage for react-native
3025

3126
import rootReducer from './reducers'
3227

3328
const persistConfig = {
3429
key: 'root',
35-
storage: storage,
30+
storage,
3631
}
3732

3833
const persistedReducer = persistReducer(persistConfig, rootReducer)
@@ -47,15 +42,9 @@ export default () => {
4742
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 />}`
4843

4944
```js
50-
import React from 'react'
51-
import { Provider } from 'react-redux'
52-
import { PersistGate } from 'redux-persist/lib/integration/react'
53-
54-
import configureStore from './store/configureStore'
55-
let { store, persistor } = configureStore()
45+
import { PersistGate } from 'redux-persist/integration/react'
5646

57-
// import your necessary custom components.
58-
import { RootComponent } from './components'
47+
// ... normal setup, create store and persistor, import components etc.
5948

6049
const App = () => {
6150
return (
@@ -66,8 +55,6 @@ const App = () => {
6655
</Provider>
6756
);
6857
};
69-
70-
export default App
7158
```
7259

7360
## API
@@ -91,33 +78,33 @@ export default App
9178

9279
#### `persistor object`
9380
- the persistor object is returned by persistStore with the following methods:
94-
- `.purge(keys)`
81+
- `.purge()`
9582
- purges state from disk and returns a promise
96-
- `flush()`
83+
- `.flush()`
9784
- immediately writes all pending state to disk and returns a promise
98-
- `pause()`
85+
- `.pause()`
9986
- pauses persistence
100-
- `persist()`
87+
- `.persist()`
10188
- resumes persistence
10289

10390
## State Reconciler
104-
State reconcilers define how incoming persisted state is merged in with existing default state. It is critical to choose the right state reconciler for your state shape. There are three options that ship out of the box, lets look at how each operates:
91+
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, lets look at how each operates:
10592

106-
1. hardSet (`import hardSet from 'redux-persist/lib/stateReconciler/hardSet'`)
93+
1. **hardSet** (`import hardSet from 'redux-persist/lib/stateReconciler/hardSet'`)
10794
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.
108-
- **INCOMING STATE**: `{ foo: incomingFoo }`
109-
- **INITIAL STATE**: `{ foo: initialFoo, bar: initialBar }`
110-
- **RECONCILED STATE**: `{ foo: incomingFoo }` // note bar has been dropped
111-
2. autoMergeLevel1 (default)
95+
- **incoming state**: `{ foo: incomingFoo }`
96+
- **initial state**: `{ foo: initialFoo, bar: initialBar }`
97+
- **reconciled state**: `{ foo: incomingFoo }` // note bar has been dropped
98+
2. **autoMergeLevel1** (default)
11299
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.
113-
- **INCOMING STATE**: `{ foo: incomingFoo }`
114-
- **INITIAL STATE**: `{ foo: initialFoo, bar: initialBar }`
115-
- **RECONCILED STATE**: `{ foo: incomingFoo, bar: initialBar }`
116-
3. autoMergeLevel2
100+
- **incoming state**: `{ foo: incomingFoo }`
101+
- **initial state**: `{ foo: initialFoo, bar: initialBar }`
102+
- **reconciled state**: `{ foo: incomingFoo, bar: initialBar }` // note incomingFoo overwrites initialFoo
103+
3. **autoMergeLevel2** (`import autoMergeLevel2 from 'redux-persist/lib/stateReconciler/autoMergeLevel2'`)
117104
This acts just like autoMergeLevel1, except it shallow merges two levels
118-
- **INCOMING STATE**: `{ foo: incomingFoo }`
119-
- **INITIAL STATE**: `{ foo: initialFoo, bar: initialBar }`
120-
- **RECONCILED STATE**: `{ foo: mergedFoo, bar: initialBar }`
105+
- **incoming state**: `{ foo: incomingFoo }`
106+
- **initial state**: `{ foo: initialFoo, bar: initialBar }`
107+
- **reconciled state**: `{ foo: mergedFoo, bar: initialBar }` // note: initialFoo and incomingFoo are shallow merged
121108

122109
#### Example
123110
```js
@@ -149,7 +136,7 @@ const persistConfig = {
149136
```
150137

151138
## Nested Persists
152-
Nested persist can be useful for a variety of reasons including different storage adapters, code splitting, or deep filtering. For example blacklist and whitelist only work one level deep, but we can use a nested persist to blacklist a deep value:
139+
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:
153140
```js
154141
import { combineReducers } from 'redux'
155142
import { persistReducer } from 'redux-persist'
@@ -183,7 +170,6 @@ export default persistReducer(rootPersistConfig, rootReducer)
183170
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)
184171

185172
## Transforms
186-
187173
Transforms allow you to customize the state object that gets persisted and rehydrated.
188174

189175
There are several libraries that tackle some of the common implementations for transforms.
@@ -216,14 +202,14 @@ const myTransform = createTransform(
216202
```
217203

218204
The createTransform function takes three parameters.
219-
1. A function that gets called right before state is persisted.
220-
2. A function that gets called right before state is rehydrated.
221-
3. A config object.
205+
1. An "inbound" function that gets called right before state is persisted.
206+
2. An "outbound" function that gets called right before state is rehydrated.
207+
3. Config.
222208

223209
## Storage Engines
224210
- **localStorage** `import storage from 'redux-persist/lib/storage'`
225-
- **sessionStorage** `import sessionStorage from 'redux-persist/lib/storage/session'`
226-
- **AsyncStorage** react-native `import storage from 'redux-persist/lib/storage'`
211+
- **sessionStorage** `import storageSession from 'redux-persist/lib/storage/session'`
212+
- **AsyncStorage** react-native `import { AsyncStorage } from 'react-native'`
227213
- **[localForage](https://github.com/mozilla/localForage)** recommended for web
228214
- **[electron storage](https://github.com/psperber/redux-persist-electron-storage)** Electron support via [electron store](https://github.com/sindresorhus/electron-store)
229215
- **[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))

integration/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Proxy package to enable
2+
```js
3+
import { PersistGate } from 'redux-persist/integration/react'
4+
```

integration/react/package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "redux-persist/integration/react",
3+
"private": true,
4+
"main": "../../lib/integration/react",
5+
"module": "../../es/integration/react",
6+
"jsnext:main": "../../es/integration/react"
7+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
},
2828
"lint-staged": {
2929
"src/**/*.js": [
30-
"prettier --no-semi --single-quote --trailing-comma --parser=flow --write",
30+
"prettier --write",
3131
"git add"
3232
]
3333
},

src/utils/curry.js

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)