🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

redux-async-initial-state

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redux-async-initial-state - npm Package Compare versions

Comparing version

to
0.2.0

2

lib/middleware.js

@@ -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: