-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstore.js
55 lines (43 loc) · 1.71 KB
/
store.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { createStore, compose, applyMiddleware } from 'redux';
import createSagaMiddleware from 'redux-saga';
import { fromJS } from 'immutable';
import storage from 'redux-storage';
import createEngine from 'redux-storage-engine-localstorage';
import merger from 'redux-storage-merger-immutablejs';
import { routerMiddleware } from 'react-router-redux';
import createReducer from './reducers';
const devtools = window.devToolsExtension || (() => noop => noop);
export default function configureStore(initialState = {}, history) {
const reactRouterMiddleware = routerMiddleware(history);
const sagaMiddleware = createSagaMiddleware();
const engine = createEngine('winterfell-formbuilder');
const storageMiddleware = storage.createMiddleware(engine);
const enhancers = [
applyMiddleware(sagaMiddleware, storageMiddleware, reactRouterMiddleware),
devtools(),
];
const reducer = storage.reducer(createReducer(), merger);
const store = createStore(
reducer,
fromJS(initialState),
compose(...enhancers),
);
// restore state from local storage if present
const load = storage.createLoader(engine);
load(store);
// start saga watchers
// Extensions
store.asyncReducers = {}; // Async reducer registry
// Make reducers hot reloadable, see http://mxs.is/googmo
if (module.hot) {
module.hot.accept('./reducers.js', () => {
require.ensure(['./reducers'], () => {
const reducerModule = require('./src/reducers/winterfellFormBuilderReducer'); // eslint-disable-line global-require
const createReducers = reducerModule.default;
const nextReducers = createReducers(store.asyncReducers);
store.replaceReducer(nextReducers);
});
});
}
return store;
}