redux-async-initial-state
Advanced tools
Comparing version
@@ -14,3 +14,3 @@ 'use strict'; | ||
}); | ||
load().then(function (state) { | ||
load(store.getState()).then(function (state) { | ||
store.dispatch({ | ||
@@ -17,0 +17,0 @@ type: _actionTypes.STATE_LOADING_DONE, |
{ | ||
"name": "redux-async-initial-state", | ||
"version": "0.1.2", | ||
"version": "0.2.0", | ||
"description": "It is simple redux middleware that helps you load redux initial state asynchronously", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -52,3 +52,3 @@ Redux Async Initial State | ||
import * as reducers from 'reducers'; | ||
import { * as asyncInitialState } from 'redux-async-initial-state'; | ||
import * as asyncInitialState from 'redux-async-initial-state'; | ||
@@ -77,2 +77,22 @@ // We need outerReducer to replace full state as soon as it loaded | ||
### Partial replace | ||
In case when you're loading only part of your store initially, you can add `currentState` argument in `loadStore` function. So, if you have some complex shape of your reducer and you need to replace only some of keys in your store (`currentUser` in example below): | ||
```js | ||
const loadStore = (currentState) => { | ||
return new Promise(resolve => { | ||
fetch('/current_user.json') | ||
.then(response => response.json()) | ||
.then(user => { | ||
resolve({ | ||
// reuse state that was before loading current user | ||
...currentState, | ||
// and replace only `currentUser` key | ||
currentUser: user | ||
}) | ||
}); | ||
}); | ||
} | ||
``` | ||
## Reducer | ||
@@ -79,0 +99,0 @@ The shape of `innerReducer` is: |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
9532
7.78%124
19.23%0
-100%