/* * @param {Object} initial state to bootstrap our stores with for server-side rendering * @param {History Object} a history object. We use `createMemoryHistory` for server-side rendering, * while using browserHistory for client-side * rendering. */ export default function configureStore(initialState, history) { // Installs hooks that always keep react-router and redux store in sync const middleware = [thunk, promiseMiddleware, routerMiddleware(history)]; let store; if (__DEVCLIENT__) { middleware.push(createLogger()); store = createStore(rootReducer, initialState, compose( applyMiddleware(...middleware), persistState(['issues']), typeof window === 'object' && typeof window.devToolsExtension !== 'undefined' ? window.devToolsExtension() : f => f )); } else { store = createStore(rootReducer, initialState, compose(applyMiddleware(...middleware), persistState(), f => f)); } if (module.hot) { // Enable Webpack hot module replacement for reducers module.hot.accept('reducers', () => { const nextReducer = require('../reducers'); store.replaceReducer(nextReducer); }); } return store; }
export function enhancer() { let enhancerWithPersistState = compose(persistState()); if (process.env.NODE_ENV === 'dev') { /* eslint-disable no-underscore-dangle */ const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose; /* eslint-enable */ enhancerWithPersistState = composeEnhancers(persistState()); } return enhancerWithPersistState; }
export default function configureStore(initialState = {}, history) { const logger = createLogger({ level: 'info', duration: true }); const reduxRouterMiddleware = syncHistory(history); //persistStateはdevToolsより上に記述 const createStoreWithMiddleware = compose( applyMiddleware(...Middlewares, thunk, promise, logger, reduxRouterMiddleware), persistState(['application']), //window.devToolsExtension ? window.devToolsExtension() : DevTools.instrument() )(createStore); const store = createStoreWithMiddleware(rootReducer, initialState); // Required for replaying actions from devtools to work reduxRouterMiddleware.listenForReplays(store) if (module.hot) { module.hot.accept('../reducers', () => { const nextReducer = require('../reducers'); store.replaceReducer(nextReducer); }); } return store; }
export default function configureStore(initialState) { const store = createStore( rootReducer, initialState, compose( applyMiddleware(thunk, reduxRouterMiddleware/*, createLogger()*/), persistState('auth'), DevTools.instrument() ) ); // Required for replaying actions from devtools to work //reduxRouterMiddleware.listenForReplays(store); if (module.hot) { // Enable Webpack hot module replacement for reducers module.hot.accept('../reducers/', () => { const nextRootReducer = require('../reducers/').default; store.replaceReducer(nextRootReducer) }) } return store; }
export default function configureStore(initialState) { const middlewares = [ // Add other middleware on this line... // Redux middleware that spits an error on you when you try to mutate your state either inside a dispatch or between dispatches. reduxImmutableStateInvariant(), // thunk middleware can also accept an extra argument to be passed to each thunk action // https://github.com/gaearon/redux-thunk#injecting-a-custom-argument thunkMiddleware, ]; const store = createStore(rootReducer, initialState, compose( applyMiddleware(...middlewares), // Save subset of state to local storage persistState(['activeAccount']), window.devToolsExtension ? window.devToolsExtension() : f => f // add support for Redux dev tools ) ); if (module.hot) { // Enable Webpack hot module replacement for reducers module.hot.accept('../reducers', () => { const nextReducer = require('../reducers').default; // eslint-disable-line global-require store.replaceReducer(nextReducer); }); } return store; }
export default function configureStore(initialState, history) { const middleware = [ thunk, promiseMiddleware, routerMiddleware(history), socketIoMiddleware, ]; const store = createStore( rootReducer, initialState, compose( applyMiddleware(...middleware), localstorage('', localStorageConfig), DevTools.instrument(), persistState( window.location.href.match( /[?&]debug_session=([^&#]+)\b/ ) ) ) ); if (module.hot) { // Enable Webpack hot module replacement for reducers /* eslint-disable global-require */ module.hot.accept('../reducers', () => { const nextRootReducer = require('../reducers'); store.replaceReducer(nextRootReducer); }); /* eslint-enable global-require */ } return store; }
export default function configureStore(initialState, localStorage = true) { /* Middleware * Configure this array with the middleware that you want included. thunk * is included by default, and react-router-redux's syncHistory is also * applied if an `options.history` object was passed to configureStore. */ let middleware = [thunk]; // Add universal enhancers here let enhancers = []; // Client-side enhancers and middleware if (isBrowser()) { if (localStorage) { enhancers.push(persistState(persistedStates)); } } const enhancer = compose(...[ applyMiddleware(...middleware), ...enhancers ]); // create store with enhancers, middleware, reducers, and initialState const store = createStore(rootReducer, initialState, enhancer); return store; }
export const configureMainTestStore = (reducer: Reducer<*, *>) => { const persistence = persistState( storage(["currentProgramEnrollment"]), "redux" ) return createPersistentTestStore(persistence)(reducer) }
function _getEnhancers() { var enhancers = [ persistState('session', _getStorageConfig()) ]; if (__DEV__ && window.devToolsExtension) { enhancers = enhancers.concat([window.devToolsExtension()]); } return enhancers; }
export default function configureStore(initialState = {}, history) { // Create the store with two middlewares // 1. sagaMiddleware: Makes redux-sagas work // 2. routerMiddleware: Syncs the location/URL path to the state const middlewares = [ sagaMiddleware, routerMiddleware(history), ]; const reducer = createReducer(); const storageKey = 'redux-state'; const storage = compose( serialize )(adapter(window.localStorage)); const enhancers = [ applyMiddleware(...middlewares), persistState(storage, storageKey), devtools(), ]; let state = fromJS(initialState); storage.get(storageKey, (err, localStorage) => { if (err) { return; } state = fromJS(localStorage).set('global', undoableHistory(localStorage.global)); }); const store = createStore( reducer, state, compose(...enhancers) ); // Create hook for async sagas store.runSaga = sagaMiddleware.run; // Make reducers hot reloadable, see http://mxs.is/googmo /* istanbul ignore next */ if (module.hot) { System.import('./reducers').then((reducerModule) => { const createReducers = reducerModule.default; const nextReducers = createReducers(store.asyncReducers); store.replaceReducer(nextReducers); }); } // Initialize it with no other reducers store.asyncReducers = {}; return store; }
export default function configureStore(initialState) { return createStore( rootReducer, initialState, compose( applyMiddleware(thunk, routerMiddleware(browserHistory)), persistState('auth') ) ); };
export function initEnhancer(persist = true, persistConfig = {}) { const { paths, config } = persistConfig; const composeEnhancers = process.env.WEBPACK_MODE === 'development' /* eslint-disable-next-line no-underscore-dangle */ ? (window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose) : compose; return persist ? composeEnhancers(persistState(paths, config)) : composeEnhancers(); }
function _getEnhancers() { const enhancers = [ persistState('session', _getStorageConfig()), ]; if (__DEV__ && window.devToolsExtension) { return [...enhancers, window.devToolsExtension() ]; } return enhancers; }
export default function configureStore (initialState) { // applyMiddleware supercharges createStore with middleware: // We can use it exactly like “vanilla” createStore. return createStore( rootReducer, initialState, compose( applyMiddleware(...middlewares), persistState(storagePaths, storageConfig) ) ) }
export default function configureStore (initialState) { const enhancer = compose(persistState(), DevTools.instrument()); const store = createStore(rootReducer, initialState, enhancer); if (module.hot) { module.hot.accept('../reducers', () => { const nextReducer = require('../reducers').default; store.replaceReducer(nextReducer); }); } return store; }
const buildStore = (history) => { const sagaMiddleware = createSagaMiddleware(); const rootReducer = combineReducers({ app: appReducer, alexandria }); const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose; const store = createStore(rootReducer, composeEnhancers( persistState('app'), applyMiddleware(sagaMiddleware))); sagaMiddleware.run(appSaga, history); return store; };
const createStore = (initialState = {}) => { // ====================================================== // Middleware Configuration // ====================================================== const middleware = [thunk, routerMiddleware(history), promise()] if (ENV === `development`) { middleware.push(createLogger()) } // ====================================================== // Store Enhancers // ====================================================== const enhancers = [persistState([ // `counter`, ])] let composeEnhancers = compose if (__DEV__) { if (typeof window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ === `function`) { composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ } } // ====================================================== // Store Instantiation and HMR Setup // ====================================================== const store = createReduxStore( makeRootReducer(), initialState, composeEnhancers( applyMiddleware(...middleware), ...enhancers ) ) store.asyncReducers = {} // To unsubscribe, invoke `store.unsubscribeHistory()` anytime store.unsubscribeHistory = browserHistory.listen(updateLocation(store)) if (module.hot) { module.hot.accept(`./reducers`, () => { const reducers = require(`./reducers`).default store.replaceReducer(reducers(store.asyncReducers)) }) } return store }
function persistStateEnhancer () { if (typeof window === 'object') { return persistState(undefined, { key: 'todos-purescript-recompose', slicer: paths => state => { // Censor the 'editing' state state.todos.todos = state.todos.todos.map(({id, title, completed}) => { return {id, title, completed} }) return state }, }) } return id => id }
return (initialState) => { const store = createStore( rootReducer, initialState, composeEnhancers( applyMiddleware(...middleware), persistState(undefined, { deserialize: deserializeStore, }), ), ); sagaMiddleware.run(rootSaga); return store; };
export default function configureStore(initialState) { const createPersistentStore = compose( persistState() )(createStore) const store = createPersistentStore(rootReducer, initialState) if (module.hot) { // Enable Webpack hot module replacement for reducers module.hot.accept('../reducers', () => { const nextReducer = require('../reducers').default store.replaceReducer(nextReducer) }) } return store }
function init () { const initialState = window.__STATE__; const reducer = redux.compose( mergePersistedState() )(rootReducer); const enhancer = redux.compose( persistState(adapter(window.localStorage), 'kabob-combos'), window.devToolsExtension ? window.devToolsExtension() : f => f ); const store = redux.createStore(reducer, initialState, enhancer); render( <App store={store} />, document.querySelector('.layout') ); }
const configureStore = (initialState) => { const container = document.getElementById('admin-article-list'); let siteId; let key = 'sherpa-article-admin-list'; if (container) { siteId = container.dataset.siteId; key += `-${siteId}`; } const middlewares = [thunk]; if (process.env.NODE_ENV !== 'production') { middlewares.push(createLogger()); } const enhancer = compose( applyMiddleware(...middlewares), persistState( ['orderField', 'page', 'threadFilter', 'nameFilter', 'completeFilter'], {key} ) ); const store = createStore( rootReducer, initialState, enhancer, ); // Enable Webpack hot module replacement for reducers if (module.hot) { module.hot.accept( './reducers', () => { const nextRootReducer = require('./reducers/index.js').default; store.replaceReducer(nextRootReducer); } ); } return store; };
export default function configureStore(initialState: ?Object) { const persistence = persistState( storage(["currentProgramEnrollment"]), "redux" ) const reducer = compose(mergePersistedState())(rootReducer) const store = createPersistentStore(persistence)(reducer, initialState) if (module.hot) { // Enable Webpack hot module replacement for reducers module.hot.accept("../reducers", () => { const nextRootReducer = require("../reducers") store.replaceReducer(nextRootReducer) }) } return store }
module.exports = function(initialState) { const store = redux.createStore( reducers, initialState, redux.compose( persistState(null, persistConfig), redux.applyMiddleware(ReduxThunk), window.devToolsExtension ? window.devToolsExtension() : f => f ) ) if (module.hot) { // Enable Webpack hot module replacement for reducers module.hot.accept('../reducers', () => { const nextReducer = require('../reducers') store.replaceReducer(nextReducer) }) } return store }
export default function configureStore(initialState) { const reducer = compose( mergePersistedState() )(rootReducer, initialState); const storage = adapter(window.localStorage); const createPersistentStore = compose( persistState(storage, 'state') )(createStore); const store = createPersistentStore(reducer); if (module.hot) { // Enable Webpack hot module replacement for reducers module.hot.accept('../reducers', () => { const nextReducer = require('../reducers').default; store.replaceReducer(nextReducer); }); } return store; }
function configureStore(initialState) { const store = compose( __DEV__ ? applyMiddleware(reduxRouterMiddleware, promiseMiddleware, thunk, tracker, logger) : applyMiddleware(reduxRouterMiddleware, promiseMiddleware, thunk, tracker), persistState('session', storageConfig) )(createStore)(rootReducer, initialState); if (module.hot) { module.hot.accept('../reducers', () => { const nextRootReducer = require('../reducers'); store.replaceReducer(nextRootReducer); }); } // Required for replaying actions from devtools to work if (__DEV__) { reduxRouterMiddleware.listenForReplays(store); } return store; }
export default function configureStore(initialState, localStorage = true) { /* Middleware * Configure this array with the middleware that you want included. thunk * is included by default, and react-router-redux's syncHistory is also * applied if an `options.history` object was passed to configureStore. */ let middleware = [thunk]; // Add universal enhancers here let enhancers = [ DevTools.instrument() ]; // Client-side enhancers and middleware if (isBrowser()) { if (localStorage) { enhancers.push(persistState(persistedStates)); } } const enhancer = compose(...[ applyMiddleware(...middleware), ...enhancers ]); // create store with enhancers, middleware, reducers, and initialState const store = createStore(rootReducer, initialState, enhancer); if (module.hot) { // Enable Webpack hot module replacement for reducers module.hot.accept('../reducers', () => { const nextRootReducer = require('../reducers').default; store.replaceReducer(nextRootReducer); }); } return store; }
function configureStore (initialState = {}, history) { // Sync with router via history instance (main.js) // const routerMiddleware = syncHistoryWithStore(history) // Compose final middleware and use devtools in debug environment let middleware = applyMiddleware(promise, routerMiddleware(history)) if (__DEBUG__) middleware = withDevTools(middleware) // Create final store and subscribe router in debug env ie. for devtools const finalCreateStore = compose( persistState() )(middleware(createStore)) const store = finalCreateStore(rootReducer, initialState) // if (__DEBUG__) routerMiddleware.listenForReplays(store, ({ router }) => router.location) if (module.hot) { module.hot.accept('./reducer', () => { const nextRootReducer = require('./reducer').default store.replaceReducer(nextRootReducer) }) } return store }
import { createStore, applyMiddleware, compose, combineReducers } from 'redux'; import thunkMiddleware from 'redux-thunk'; import persistState from 'redux-localstorage'; import { reducer as formReducer } from 'redux-form'; import * as reducers from './reducers'; const reducer = combineReducers({ ...reducers, form: formReducer, }); const createStoreWithMiddlewares = compose( applyMiddleware(thunkMiddleware), // applyMiddleware(logoutOnInvalidAuthHeader), persistState(['session']), window.devToolsExtension ? window.devToolsExtension() : f => f, )(createStore); export default createStoreWithMiddlewares(reducer);
const createPersistentStore = () => { return persistState(storage, STORAGE_KEY) }