/*
 * @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;
}
Example #2
0
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;
}
Example #3
0
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;
}
Example #4
0
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;
}
Example #6
0
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;
}
Example #8
0
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;
}
Example #10
0
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;
}
Example #11
0
export default function configureStore(initialState) {
	return createStore(
		rootReducer,
		initialState,
		compose(
			applyMiddleware(thunk, routerMiddleware(browserHistory)),
			persistState('auth')
		)
	);
};
Example #12
0
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();
}
Example #13
0
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)
    )
  )
}
Example #15
0
File: store.dev.js Project: hph/kit
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;
}
Example #16
0
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
}
Example #19
0
  return (initialState) => {
    const store = createStore(
      rootReducer,
      initialState,
      composeEnhancers(
        applyMiddleware(...middleware),
        persistState(undefined, {
          deserialize: deserializeStore,
        }),
      ),
    );

    sagaMiddleware.run(rootSaga);

    return store;
  };
Example #20
0
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
}
Example #21
0
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')
  );
}
Example #22
0
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;
};
Example #23
0
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
}
Example #24
0
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
}
Example #25
0
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;
}
Example #28
0
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
}
Example #29
0
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);
Example #30
0
const createPersistentStore = () => {
  return persistState(storage, STORAGE_KEY)
}