forked from phated/redux-create-store
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (29 loc) · 959 Bytes
/
index.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
'use strict';
var redux = require('redux');
var promiseMiddleware = require('redux-promise');
var defaultEnhancers = [];
var defaultMiddleware = [promiseMiddleware];
function createStore(reducers, config){
config = config || {};
var extraEnhancers = config.enhancers;
if(extraEnhancers == null){
extraEnhancers = [];
}
var extraMiddleware = config.middleware;
if(extraMiddleware == null){
extraMiddleware = [];
}
var reducer;
if(typeof reducers === 'function'){
reducer = reducers;
} else {
reducer = redux.combineReducers(reducers);
}
var middleware = defaultMiddleware.concat(extraMiddleware);
var middlewareStack = redux.applyMiddleware.apply(null, middleware);
var enhancers = defaultEnhancers.concat(middlewareStack, extraEnhancers);
var composed = redux.compose.apply(null, enhancers);
var storeCreator = composed(redux.createStore);
return storeCreator(reducer);
}
module.exports = createStore;