Skip to content

Commit

Permalink
Add an option to delay the automatic persistence. (#986)
Browse files Browse the repository at this point in the history
* add an option to deactivate the automatic start

* document the new manualPersist option in the readme
  • Loading branch information
leoek authored and rt2zz committed Jul 5, 2019
1 parent 5a5f463 commit 7bbf971
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const App = () => {
- arguments
- **store** *redux store* The store to be persisted.
- **config** *object* (typically null)
- 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.
- **callback** *function* will be called after rehydration is finished.
- returns **persistor** object

Expand Down
6 changes: 4 additions & 2 deletions src/persistStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default function persistStore(
let _pStore = createStore(
persistorReducer,
initialState,
options ? options.enhancer : undefined
options && options.enhancer ? options.enhancer : undefined
)
let register = (key: string) => {
_pStore.dispatch({
Expand Down Expand Up @@ -122,7 +122,9 @@ export default function persistStore(
},
}

persistor.persist()
if (!(options && options.manualPersist)){
persistor.persist()
}

return persistor
}
1 change: 1 addition & 0 deletions src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export type PersistConfig = {

export type PersistorOptions = {
enhancer?: Function,
manualPersist?: boolean
}

export type Storage = {
Expand Down

0 comments on commit 7bbf971

Please sign in to comment.