Skip to content

Instantly share code, notes, and snippets.

@kopax
Created March 20, 2019 09:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kopax/48f367f62d05b2d6d3373d7e5456a460 to your computer and use it in GitHub Desktop.
Save kopax/48f367f62d05b2d6d3373d7e5456a460 to your computer and use it in GitHub Desktop.
export default ({
dataProvider,
history,
customReducers = {},
authProvider = null,
customSagas = [],
i18nProvider = defaultI18nProvider,
initialState,
locale = 'en',
}) => {
const messages = i18nProvider(locale);
const appReducer = createAppReducer(customReducers, locale, messages);
const persistedReducer = persistReducer(persistConfig, appReducer);
const resettableAppReducer = (state, action) =>
persistedReducer(action.type !== USER_LOGOUT ? state : undefined, action);
const saga = function* rootSaga() {
yield all(
[
adminSaga(dataProvider, authProvider, i18nProvider),
...customSagas,
].map(fork)
);
};
const sagaMiddleware = createSagaMiddleware();
const typedWindow = window;
const store = createStore(
resettableAppReducer,
initialState,
compose(
applyMiddleware(
sagaMiddleware,
formMiddleware,
routerMiddleware(history)
),
typeof typedWindow !== 'undefined' &&
typedWindow.__REDUX_DEVTOOLS_EXTENSION__
? typedWindow.__REDUX_DEVTOOLS_EXTENSION__()
: f => f
)
);
sagaMiddleware.run(saga);
window.persistor = persistStore(store);
return store;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment