forked from busyorg/busy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
store.js
57 lines (51 loc) · 1.42 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
56
57
import promiseMiddleware from 'redux-promise-middleware';
import thunk from 'redux-thunk';
import { applyMiddleware, createStore, compose } from 'redux';
import { routerMiddleware } from 'react-router-redux';
import api from './steemAPI';
import { history } from './routes';
import { mountResponsive } from './vendor/responsive';
import errorMiddleware from './errorMiddleware';
import reducers from './reducers';
let preloadedState;
if (process.env.IS_BROWSER) {
/* eslint-disable no-underscore-dangle */
preloadedState = window.__PRELOADED_STATE__;
delete window.__PRELOADED_STATE__;
/* eslint-enable no-underscore-dangle */
}
if (process.env.IS_BROWSER && process.env.NODE_ENV !== 'production') {
window.steemAPI = api;
}
const middleware = [
errorMiddleware,
promiseMiddleware({
promiseTypeSuffixes: [
'START',
'SUCCESS',
'ERROR',
],
}),
thunk.withExtraArgument({
steemAPI: api,
}),
routerMiddleware(history),
];
let enhancer;
if (process.env.IS_BROWSER) {
// eslint-disable-next-line no-underscore-dangle
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
enhancer = composeEnhancers(applyMiddleware(...middleware));
} else {
enhancer = compose(applyMiddleware(...middleware));
}
const getStore = () => {
const store = createStore(
reducers,
preloadedState,
enhancer,
);
mountResponsive(store);
return store;
};
export default getStore;