Beispiel #1
0
export default initialState => {
  let store;
  const reducer = makeReducer();
  const reduxRouterMiddleware = syncHistory(browserHistory);

  const middlewares = [
    reduxRouterMiddleware,
    optimisticMiddleware,
    thunkMiddleware
  ];

  if (!__PRODUCTION__) {
    const devtoolsExt = global.devToolsExtension && global.devToolsExtension();
    if (!devtoolsExt) {
      // We don't have the Redux extension in the browser, show the Redux logger
      const createLogger = require('redux-logger');
      const logger = createLogger({
        level: 'info',
        collapsed: true
      });
      middlewares.push(logger);
    }
    store = createStore(reducer, initialState, compose(
      applyMiddleware(...middlewares),
      devtoolsExt || (f => f)
    ));
    reduxRouterMiddleware.listenForReplays(store, state => ensureState(state).get('routing'));
  } else {
    store = createStore(reducer, initialState, applyMiddleware(...middlewares));
  }
  return store;
};
function configureStore(initState) {

  let finalCreateStore

  // Sync dispatched route actions to the history
  const reduxRouterMiddleware = syncHistory(history)

  if(__DEV__) {
    //const createLogger = require('redux-logger')
    const allDevTools = require('../containers/DevTools')
    finalCreateStore = compose(
      applyMiddleware(
        reduxRouterMiddleware,
        thunk,
        /* createLogger(), */
      ),
      allDevTools.DevTools.instrument(),
      allDevTools.persistState(allDevTools.getDebugSessionKey()),
    )(createStore)

  } else {
    finalCreateStore = compose(
      applyMiddleware(
        reduxRouterMiddleware,
        thunk,
      ),
    )(createStore)
  }

  const store = finalCreateStore(rootReducer, initState)

  if (module.hot) {
    // Enable Webpack hot module replacement for reducers
    module.hot.accept('../reducers', () => {
      window.rootCombineReducer.user = require('../reducers/user')
      const nextReducer = combineReducers(window.rootCombineReducer)
      store.replaceReducer(nextReducer)
    })
  }

  return store
}
export default (req, initialState) => {
    console.log('Server router!');
    const rootReducer = combineReducers(Object.assign({}, reducers, {
        routing: routeReducer
    }));

    const reduxRouterMiddleware = syncHistory(createHistory());

    let enhancer = compose(
        applyMiddleware(thunkMiddleware, reduxRouterMiddleware)
    );

    if (process.env.NODE_ENV !== 'production') {
        enhancer = compose(
            applyMiddleware(thunkMiddleware, reduxRouterMiddleware),
            DevTools.instrument()
        );
    }
    return createStore(rootReducer, initialState, enhancer);
};
Beispiel #4
0
export default function configureStore ({ initialState = {}, history }) {
  // Sync with router via history instance (main.js)
  const routerMiddleware = syncHistory(history)

  // Compose final middleware and use devtools in debug environment
  let middleware = applyMiddleware(thunk, routerMiddleware)
  if (__DEBUG__) middleware = withDevTools(middleware)

  // Create final store and subscribe router in debug env ie. for devtools
  const store = middleware(createStore)(rootReducer, initialState)
  if (__DEBUG__) routerMiddleware.listenForReplays(store, ({ router }) => router)

  if (module.hot) {
    module.hot.accept('./rootReducer', () => {
      const nextRootReducer = require('./rootReducer').default

      store.replaceReducer(nextRootReducer)
    })
  }
  return store
}
export default function createStore(history, clientApi, data) {
  // Sync dispatched route actions to the history
  const reduxRouterMiddleware = syncHistory(history);

  const middleware = [createMiddleware(clientApi), reduxRouterMiddleware, authMiddleware];

  let finalCreateStore;
  if (__DEVELOPMENT__ && __CLIENT__ && __DEVTOOLS__) {
    const { persistState } = require('redux-devtools');
    const DevTools = require('../containers/DevTools/DevTools');
    finalCreateStore = compose(
      applyMiddleware(...middleware),
      window.devToolsExtension ? window.devToolsExtension() : DevTools.instrument(),
      persistState(window.location.href.match(/[?&]debug_session=([^&]+)\b/))
    )(_createStore);
  } else {
    finalCreateStore = applyMiddleware(...middleware)(_createStore);
  }

  const reducer = require('./modules/reducer');
  const store = finalCreateStore(reducer, data);

  // Required for replaying actions from devtools to work
  reduxRouterMiddleware.listenForReplays(store);

  if (__DEVELOPMENT__ && module.hot) {
    module.hot.accept('./modules/reducer', () => {
      store.replaceReducer(require('./modules/reducer'));
    });
  }

  // ( ͡° ͜ʖ ͡°)
  global.APP_STORE = store;

  return store;
}
Beispiel #6
0
export function stores (options = {}) {
  let { initialState, reducers, history, middlewares, project } = options

  invariant(isArray(reducers), 'Pass an array of reducers')
  invariant(isArray(initialState) && reducers.length === initialState.length, 'Pass an array of initial state objects for each reducer')

  const router = {router: routeReducer}
  const defaultMiddlewares = [thunk, syncHistory(history)]

  const appReducers = reducers.length > 0
    ? assign(router, ...reducers)
    : router

  const appState = initialState.length > 0
    ? assign({}, ...initialState)
    : {}

  const appMiddlewares = middlewares && middlewares.length > 0
    ? defaultMiddlewares.concat(middlewares)
    : defaultMiddlewares

  if (project) {
     appState.assets = project.assets
     appState.content = project.content
     appState.entities = project.entities
     appState.models = project.models
     appState.project = project.project
     appState.settings = project.settings
  }

  return compose(applyMiddleware(...appMiddlewares), window.devToolsExtension ? window.devToolsExtension() : f => f)(createStore)(

    combineReducers(appReducers),
    pick(appState, keys(appReducers))
  )
}
import {Provider} from "react-redux";
import thunk from "redux-thunk";
import {syncHistory} from "redux-simple-router";

import {setupIncrementalReduxReducers, addReducer} from "incremental-redux-reducers";

import routeReducer from "./routeReducer";
import history from "./history";

import analytics from "./analytics";

import "./application/style.less";

import routingConfiguration from "pegasus!.";

const reduxRouterMiddleware = syncHistory(history);

const createStoreWithMiddleware = applyMiddleware(
  thunk
, reduxRouterMiddleware
)(createStore);

// no-op reducer to be overridden by incremental-redux-reducers
const store = createStoreWithMiddleware(() => {});

setupIncrementalReduxReducers(store);

function handleRouterUpdate() {
  analytics("send", "pageview");
}
import { createStore, applyMiddleware, compose, combineReducers } from 'redux'
import { syncHistory, routeReducer } from 'redux-simple-router'
import browserHistory from '../misc/browserHistory'
import DevTools from '../containers/DevTools'
import thunk from 'redux-thunk'
import createLogger from 'redux-logger'
import promiseMiddleware from 'redux-promise-middleware';
import rootReducer from './rootReducer'
import { paginationMiddleware } from '../modules/core/ducks/lazyPagination'

const reduxRouterMiddleware = syncHistory(browserHistory);

const finalCreateStore = compose(
  applyMiddleware(
    thunk,
    promiseMiddleware({promiseTypeSuffixes: ['START', 'SUCCESS', 'ERROR']}),
    paginationMiddleware
  ),
  applyMiddleware(reduxRouterMiddleware)
)(createStore);

export default function configureStore(initialState) {
  const store = finalCreateStore(rootReducer, initialState);

  // Required for replaying actions from devtools to work
  reduxRouterMiddleware.listenForReplays(store);

  return store
}
Beispiel #9
0
export default function (initialState) {
  const reduxRouterMiddleware = syncHistory(browserHistory)
  const createStoreWithMiddleware = applyMiddleware(reduxRouterMiddleware, optimisticMiddleware, thunkMiddleware)(createStore);
  return createStoreWithMiddleware(makeReducer(), initialState);
}
export default (history, initialState) => {
  const createStoreWithMiddleware = applyMiddleware(thunk, syncHistory(history), apiMiddleware)(createStore);

  return createStoreWithMiddleware(reducer, initialState);
};
Beispiel #11
0
import { compose, createStore, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';

import { createHistory } from 'history';
import useStandardScroll from 'scroll-behavior/lib/useStandardScroll';
import { Router, IndexRoute, Route } from 'react-router';
import { syncHistory, routeReducer } from 'redux-simple-router';
import createLogger from 'redux-logger';

import App from './containers/App.react';
import SearchPage from './containers/SearchPage.react';
import ResearchPage from './containers/ResearchPage.react';
import rootReducer from './reducers/';

const history = useStandardScroll(createHistory)();
const syncHist = syncHistory(history)
const middleware = [syncHist, thunk, createLogger()]

const finalCreateStore = compose(applyMiddleware(...middleware))(createStore)

const store = finalCreateStore(rootReducer)

render(
    <Provider store={store}>
        <Router history={history}>
            <Route path="/" component={App}>
               <IndexRoute component={SearchPage}/>
               <Route path="research-page" component={ResearchPage}/>
            </Route>
        </Router>
    </Provider>,
Beispiel #12
0
import { compose, applyMiddleware, createStore } from 'redux';
import rootReducer from '../reducers/root.js';
import promise from 'redux-promise';
import createLogger from 'redux-logger';
import * as workspaceActions from '../actions/workspace.js';
import { playingMode, toolMode } from '../../utils';

import { browserHistory } from 'react-router';
import { syncHistory } from 'redux-simple-router';

let middlewares = [promise];

const reduxRouter = syncHistory(browserHistory);
middlewares.push(reduxRouter);

if (process.env.NODE_ENV != 'production') {
    const createLogger = require('redux-logger');
    const logger = createLogger({collapse:true});
    // middlewares.push(logger);
}

const devTools = window.devToolsExtension ? window.devToolsExtension() : f => f;

// Create store
let store = createStore(rootReducer, compose(applyMiddleware(...middlewares), devTools));

// Dispatch actions to set up workspace initially
store.dispatch(workspaceActions.setPlayingMode(playingMode.STOP));
store.dispatch(workspaceActions.setToolMode(toolMode.CURSOR));
store.dispatch(workspaceActions.setSeeker(0));
store.dispatch(workspaceActions.setZoom(1));