import {
createStore,
applyMiddleware,
combineReducers
} from '../utils/rx';
|
import thunk from 'redux-thunk';
|
import { hashHistory } from 'react-router';
import { routerMiddleware, routerReducer } from 'react-router-redux';
|
import promiseMiddleware from 'redux-promise-middleware';
import { loadingBarReducer } from 'react-redux-loading-bar';
import { loadingBarMiddleware } from './loadingBarMiddleware';
|
import { createReducerAndModels } from './createReducerFactory';
import enhanceStore from './enhanceStore';
let appStore;
export default function configureStore(initialState, storeMiddlewares, createReducer) {
if(appStore) return appStore;
const router = routerMiddleware(hashHistory);
const enhancer = applyMiddleware(thunk, router, ...storeMiddlewares, promiseMiddleware(), loadingBarMiddleware({promiseTypeSuffixes: ['START', 'SUCCESS', 'ERROR']}));
|
const { Models } = createReducer();
let { reducers, models } = createReducerAndModels({routing: routerReducer, loadingBar: loadingBarReducer}, Models);
const rootReducer = combineReducers(reducers);
appStore = createStore(rootReducer, initialState, enhancer);
enhanceStore(appStore, models, reducers);
return appStore;
}
configureStore.replace = function(appStore, Models){
let { reducers, models } = createReducerAndModels({routing: routerReducer, loadingBar: loadingBarReducer}, Models);
const rootReducer = combineReducers(reducers);
appStore.replaceReducer(rootReducer);
Object.assign(appStore.models, models);
}
|