Skip to content

Commit 7bbf971

Browse files
leoekZack Story
authored andcommitted
Add an option to delay the automatic persistence. (#986)
* add an option to deactivate the automatic start * document the new manualPersist option in the readme
1 parent 5a5f463 commit 7bbf971

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ const App = () => {
7474
- arguments
7575
- **store** *redux store* The store to be persisted.
7676
- **config** *object* (typically null)
77+
- If you want to avoid that the persistence starts immediatly after calling `persistStore`, set the option manualPersist. Example: `{ manualPersist: true }` Persistence can than be started at any point with `peristor.persist()`. You usually want to do this, if your storage is not ready when the `persisStore` call is made.
7778
- **callback** *function* will be called after rehydration is finished.
7879
- returns **persistor** object
7980

src/persistStore.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export default function persistStore(
6565
let _pStore = createStore(
6666
persistorReducer,
6767
initialState,
68-
options ? options.enhancer : undefined
68+
options && options.enhancer ? options.enhancer : undefined
6969
)
7070
let register = (key: string) => {
7171
_pStore.dispatch({
@@ -122,7 +122,9 @@ export default function persistStore(
122122
},
123123
}
124124

125-
persistor.persist()
125+
if (!(options && options.manualPersist)){
126+
persistor.persist()
127+
}
126128

127129
return persistor
128130
}

src/types.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export type PersistConfig = {
3131

3232
export type PersistorOptions = {
3333
enhancer?: Function,
34+
manualPersist?: boolean
3435
}
3536

3637
export type Storage = {

0 commit comments

Comments
 (0)