Skip to content

Instantly share code, notes, and snippets.

@anujraghuvanshi
Forked from steniowagner/store.js
Created July 16, 2021 04:56
Show Gist options
  • Select an option

  • Save anujraghuvanshi/ecd23fd0971fa2eba8d51b89a2aa65e2 to your computer and use it in GitHub Desktop.

Select an option

Save anujraghuvanshi/ecd23fd0971fa2eba8d51b89a2aa65e2 to your computer and use it in GitHub Desktop.
Basic setup of Redux-Store + Redux-Persist + Redux-Saga. You can find a snippet that use this configuration here: https://gist.github.com/steniowagner/e778fcae0d8eb77b82da983fb46c2826
import { createStore, applyMiddleware, compose } from 'redux';
import createSagaMiddleware from 'redux-saga';
import { persistStore, persistCombineReducers } from 'redux-persist';
import storage from 'redux-persist/es/storage';
import rootSaga from './sagas';
/* Reducers */
import { reducer as coachProfile } from './ducks/coach-profile';
import { reducer as player } from './ducks/player';
import { reducer as fileManager } from './ducks/file-manager';
const reducers = {
coachProfile,
player,
fileManager,
};
/* Redux-Persist */
const rootReducer = persistCombineReducers({
key: 'root',
storage,
}, reducers);
const middlewares = [];
const enhancers = [];
/* Saga */
const sagaMonitor = __DEV__ ? console.tron.createSagaMonitor() : null;
const sagaMiddleware = createSagaMiddleware({ sagaMonitor });
middlewares.push(sagaMiddleware);
enhancers.push(applyMiddleware(...middlewares));
/* Create Store */
const createAppropriateStore = __DEV__ ? console.tron.createStore : createStore;
export const store = createAppropriateStore(
rootReducer,
compose(...enhancers),
);
/* Redux-Persist + Store */
export const persistor = persistStore(store);
/* Run saga */
sagaMiddleware.run(rootSaga);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment