Esempio n. 1
1
export function configureStore(initialState = {}, debug = IS_DEVELOPMENT) {
  const envMiddlewares = {
    dev: [thunk.withExtraArgument(axios), routerMiddleware(history)],
    prod: [thunk.withExtraArgument(axios), routerMiddleware(history)],
  }

  const storeEnhancers = debug
    ? compose(
        applyMiddleware(...envMiddlewares.dev),
        window.devToolsExtension ? window.devToolsExtension() : f => f
      )
    : compose(applyMiddleware(...envMiddlewares.prod))

  const store = createStore(connectRouter(history)(rootReducer), initialState, storeEnhancers)

  if (module.hot) {
    // Enable Webpack hot module replacement for reducers
    module.hot.accept('./redux', () => {
      const nextRootReducer = require('./redux/index').rootReducer // eslint-disable-line
      store.replaceReducer(nextRootReducer)
    })
  }

  return store
}
Esempio n. 2
0
export default () => {
  const sagaMiddleware = createSagaMiddleware();
  // eslint-disable-next-line no-underscore-dangle
  const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
  const store = createStore(
    connectRouter(history)(reducer),
    composeEnhancers(
      applyMiddleware(
        status,
        routerMiddleware(history),
        sagaMiddleware,
      ),
    ),
  );

  if (module.hot) {
    module.hot.accept('store/reducers', () => {
      const nextReducer = require('store/reducers').default; // eslint-disable-line global-require
      store.replaceReducer(nextReducer);
    });
  }

  sagaMiddleware.run(rootSaga);

  return store;
};
export default initialState =>
  createStore(
    combineReducers({
      router: connectRouter(history),
      ...reducers,
    }),
    initialState,
    composeEnhancers(applyMiddleware(routerMiddleware(history), thunk)),
  )
Esempio n. 4
0
export function createReduxStore(initialState = {}) {
    return createStore(
        connectRouter(history)(rootReducer),
        initialState, // initial state
        compose(
            applyMiddleware(
                routerMiddleware(history),
                thunkMiddleware,
            )
        )
    );
}
export default function configureStore(preloadState) {
	const store = createStore(
		createRootReducer(history),
		preloadState,
		compose(
			applyMiddleware(
				routerMiddleware(history)
			),
			applyMiddleware(thunk),
			window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__() //eslint-disable-line
		)
	);

	return store;
}
export default function createStore({
  history = createMemoryHistory(),
  initialState = {},
}: CreateStoreParams = {}) {
  const sagaMiddleware = createSagaMiddleware();
  const store = _createStore(
    createRootReducer({ history, reducers }),
    initialState,
    middleware({
      routerMiddleware: routerMiddleware(history),
      sagaMiddleware,
    }),
  );

  return { sagaMiddleware, store };
}
export default function configureStore() {
  const sagaMiddleware = createSagaMiddleware();

  const store = createStore(
    connectRouter(history)(rootReducer),
    composeEnhancers(
      applyMiddleware(
        routerMiddleware(history),
        sagaMiddleware
      ),
    ),
  );
  sagaMiddleware.run(saga);

  return store;
}
Esempio n. 8
0
/**
 * Create the redux store of the RB module.
 *
 * @param {Object} overrides - overrides provided by e.g. a plugin
 * @param {Array} additionalReducers - additional reducers provided by
 * e.g. a plugin
 */
export default function createRBStore(overrides = {}, additionalReducers = []) {
    return createReduxStore(
        'rb-new',
        getReducers(history),
        {_overrides: overrides},
        [
            routerMiddleware(history),
            queryStringMiddleware(history, getRouteConfig(), {usePush: false})
        ],
        [
            qsRoomSearchReducer,
            qsBookRoomReducer,
            qsCalendarReducer,
            qsBlockingsReducer,
            ...additionalReducers
        ]);
}
function createStoreAndSagas({
  history = createHistory({ req: { url: '' } }),
  reducers = {
    api: apiReducer,
    survey: surveyReducer,
    users: usersReducer,
  },
} = {}) {
  const sagaMiddleware = createSagaMiddleware();
  const store = createStore(
    connectRouter(history)(combineReducers(reducers)),
    // Do not define an initial state.
    undefined,
    middleware({
      routerMiddleware: routerMiddleware(history),
      sagaMiddleware,
    }),
  );

  return { store, sagaMiddleware };
}
Esempio n. 10
0
File: index.js Progetto: ikit/tests
app.get(/^\/.*/, (req, res, next) => {

	// On crée un store spécifique pour le rendu serveur
	// comme on est pas dans un navigateur, on utilise memoryHistory au lieu browserHistory
	const memoryHistory = createMemoryHistory({initialEntries: [req.originalUrl]});
	const store = createStore(
		connectRouter( memoryHistory )( reducer ),
		applyMiddleware( thunk, routerMiddleware( memoryHistory ) )
	);

	// On teste l'url demandée (req.path) avec les différentes routes de l'application
	// On utilise pour ça la fonction matchPath de React Router
	// Dès qu'une route correspond à l'url demandée, on note la méthode fetchData pour exécution ultérieure
	const promises = [];
	const routeFound = routes.some( route => {
		const match = matchPath( req.path, route );
		if ( match && route.component.fetchData ) {
			promises.push( route.component.fetchData( store, match.params ) );
		}
		return match;
	})

	// on exécute les méthodes fetchData éventuelles
	Promise.all( promises ).then( () => {
		res.status(routeFound ? 200 : 404).send(
			// puis on génère le code html avec le state pré-calculé
			page(
				renderToString(
					<Provider store={store}>
						<ConnectedRouter history={memoryHistory}>
							<Layout />
						</ConnectedRouter>
					</Provider>
				),
				store.getState()
			)
		);
	});
});
Esempio n. 11
0
export default function configureStore(
  initialState: Object = {},
  plugins: Plugin[] = []
) {
  // Each plugin exports a `reducers` attribute.
  const pluginReducers = plugins.map(({ reducers = {} }) => reducers);
  // Each plugin exports a `sagas` attribute.
  const pluginSagas = plugins.map(({ sagas = [] }) => sagas);

  const finalCreateStore = compose(
    applyMiddleware(sagaMiddleware, routerMiddleware(hashHistory)),
    window.devToolsExtension ? window.devToolsExtension() : f => f
  )(createStore);

  const store = finalCreateStore(
    connectRouter(hashHistory)(createRootReducer(pluginReducers)),
    initialState
  );
  // Every saga will receive the store getState() function as first argument
  // by default; this allows sagas to share the same signature and access the
  // state consistently.
  sagaMiddleware.run(rootSaga, store.getState.bind(store), pluginSagas);
  return store;
}
Esempio n. 12
0
import { createBrowserHistory } from 'history';
import { applyMiddleware, compose, createStore } from 'redux';
import { routerMiddleware } from 'connected-react-router';

import createRootReducer from './reducers';

export const history = createBrowserHistory();

const middleware = [routerMiddleware(history)];

const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
const enhancer = composeEnhancers(
  applyMiddleware(...middleware)
);

const configureStore = (initialState) => {
  const store = createStore(
    createRootReducer(history),
    initialState,
    enhancer
  );

  // Hot reload reducers (requires Webpack or Browserify HMR to be enabled)
  if (module.hot) {
    module.hot.accept('./reducers', () =>
      store.replaceReducer(require('./reducers'))
    );
  }

  return store;
};
Esempio n. 13
0
import {connectRouter, routerMiddleware} from 'connected-react-router'
import Immutable from 'seamless-immutable'
import thunk from 'redux-thunk'
import history from './history'
import reducer from './reducers/reducer'

const getCompose = () => {
  if (
    typeof window === 'object' &&
    window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
  ) {
    return window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
  }
  return compose
}

const composeEnhancers = getCompose()

const store = createStore(
  connectRouter(history)(reducer), // new root reducer with router state
  Immutable(),
  composeEnhancers(
    applyMiddleware(
      routerMiddleware(history), // for dispatching history actions
      thunk
    )
  )
)

export default store
Esempio n. 14
0
import { createHashHistory } from "history";
import { routerMiddleware } from "connected-react-router";

export const history = createHashHistory();

export const historyMiddleware = routerMiddleware(history);
Esempio n. 15
0
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { applyMiddleware, compose, createStore } from 'redux';
import { Route } from 'react-router-dom';
import { routerMiddleware, connectRouter } from 'connected-react-router';
import thunk from 'redux-thunk';
import { createBrowserHistory } from 'history';
import { ConnectedRouter } from 'connected-react-router';
import rootReducer from './reducers';
import App from './app';

const history = createBrowserHistory();

const composeEnhancer = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
const store = createStore(
  connectRouter(history)(rootReducer),
  applyMiddleware(thunk),
  composeEnhancer(applyMiddleware(routerMiddleware(history)))
);

ReactDOM.render(
  <Provider store={store}>
    <ConnectedRouter history={history}>
      <Route component={App} />
    </ConnectedRouter>
  </Provider>,
  document.getElementById('root')
);
// import createHistory from 'history/createHashHistory';
import createHistory from 'history/createBrowserHistory';
// #endregion
import { persistReducer, persistStore } from 'redux-persist';
import storage from 'redux-persist/lib/storage'; // defaults to localStorage for web
import reducer from '../modules/reducers';
import fetchMiddleware from '../middleware/fetchMiddleware';
// #endregion

// #region constants
export const history = createHistory();
// #endregion

// #region createStore : enhancer
const enhancer = composeWithDevTools(
  applyMiddleware(thunkMiddleware, fetchMiddleware, routerMiddleware(history)),
);
// #endregion

// #region persisted reducer
const persistConfig = {
  key: 'root',
  storage,
  blacklist: ['router'],
  // whitelist: ['userAuth'],
};

const persistedReducer = persistReducer(
  persistConfig,
  connectRouter(history)(reducer),
);
Esempio n. 17
0
import { createStore, combineReducers, applyMiddleware, compose } from "redux"
import thunk from "redux-thunk"
import { connectRouter, routerMiddleware } from "connected-react-router"
import { composeWithDevTools } from "redux-devtools-extension"
import { i18nState } from "redux-i18n"
import user from "redux/modules/user"
import photos from 'redux/modules/photos'
import createHistory from "history/createBrowserHistory"

const env = process.env.NODE_ENV

const history = createHistory()
const middlewares = [thunk, routerMiddleware(history)]

if (env === "development") {
  const { logger } = require("redux-logger")
  middlewares.push(logger)
}

const reducer = combineReducers({
  user,
  photos,
  i18nState
})

let store

if (env === "development") {
  store = initialState =>
    createStore(
      connectRouter(history)(reducer),
Esempio n. 18
0
import thunk from "redux-thunk";
import { createBrowserHistory } from "history";

import { createStore, applyMiddleware } from "redux";
import { composeWithDevTools } from "redux-devtools-extension/logOnlyInProduction";
import { connectRouter, routerMiddleware } from "connected-react-router";

import reducers from "../reducers";

export const history = createBrowserHistory();
const initialState = {};

// applyMiddleware(thunk, middleware)

const composeEnhancers = composeWithDevTools({
  // options like actionSanitizer, stateSanitizer
});

const store = createStore(
  connectRouter(history)(reducers),
  initialState,
  composeEnhancers(applyMiddleware(thunk, routerMiddleware(history)))
);

export default store;
Esempio n. 19
0
import { applyMiddleware, compose, createStore } from 'redux';
import thunkMiddleware from 'redux-thunk';
import { createLogger } from 'redux-logger';
import { connectRouter, routerMiddleware } from 'connected-react-router';

import history from './history';
import rootReducer from './rootReducer';


const loggerMiddleware = createLogger();

export default createStore(
    connectRouter(history)(rootReducer),
    {}, // initial state
    compose(
        applyMiddleware(
            routerMiddleware(history),
            thunkMiddleware,
            loggerMiddleware,
        )
    )
);
Esempio n. 20
0
import React from 'react' //eslint-disable-line no-unused-vars
import { render } from 'react-dom'
import { Provider } from 'react-redux'
import { createBrowserHistory } from 'history'
import { createStore, applyMiddleware, compose } from 'redux'
import { connectRouter, routerMiddleware, ConnectedRouter } from 'connected-react-router'
import thunkMiddleware from 'redux-thunk'
import rootReducer from './src/reducers'
import AppContainer from './src/AppContainer'

const history = createBrowserHistory()
const store = createStore(connectRouter(history)(rootReducer), window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__(), compose(applyMiddleware(routerMiddleware(history), thunkMiddleware)))

render(
    <Provider store={store}>
        <ConnectedRouter history={history}>
            <AppContainer />
        </ConnectedRouter>
    </Provider>,
    document.getElementById('root')
)
import { createStore, compose, applyMiddleware } from 'redux';
import { routerMiddleware } from 'connected-react-router';
import createSagaMiddleware from 'redux-saga';

import sagas from './sagas';
import reducers from './ducks';
import history from '../routes/history';

const sagaMiddleware = createSagaMiddleware();

const middlewares = [sagaMiddleware, routerMiddleware(history)];

const createAppropriateStore = createStore;

const store = createAppropriateStore(reducers(history), compose(applyMiddleware(...middlewares)));

sagaMiddleware.run(sagas);

export default store;