ih-black-lion
Version:
State handler for Arus projects
37 lines (30 loc) • 1.25 kB
JavaScript
import { createStore, applyMiddleware } from 'redux';
import { getStoredState, persistStore } from 'redux-persist';
import createSagaMiddleware from 'redux-saga';
import models from './lib/models';
import reducers from './lib/reducers';
import actions from './lib/actions';
import rootSaga from './lib/sagas';
const NavigationCollection = models.NavigationCollection;
export { NavigationCollection };
/* I've combined the actions and reducers elsewhere to lower the noise in this file. */
export { actions, reducers };
const persistConfig = {};
const sagaMiddleware = createSagaMiddleware();
const middleware = applyMiddleware(sagaMiddleware);
export const blackLionCreateStore = middleware(createStore);
export const initBlackLionCaching = (
cb,
config = persistConfig,
finalCreateStore = blackLionCreateStore /* TODO: Have the redux devtools be available under a dev environment only. */,
) =>
getStoredState(config, (err, restoredState) => {
const store = finalCreateStore(
reducers,
restoredState,
window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__(),
);
sagaMiddleware.run(rootSaga);
const storePersistor = persistStore(store, config);
cb(store, storePersistor);
});