redux#applyMiddleware JavaScript Examples

The following examples show how to use redux#applyMiddleware. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.js    From fhir-app-starter with MIT License 6 votes vote down vote up
export default function configureStore(initialState = {}, history) {
  let composeEnhancers = compose;
  const reduxSagaMonitorOptions = {};

  // If Redux Dev Tools and Saga Dev Tools Extensions are installed, enable them
  /* istanbul ignore next */
  if (process.env.NODE_ENV !== 'production' && typeof window === 'object') {
    /* eslint-disable no-underscore-dangle */
    if (window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__)
      composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({});

    // NOTE: Uncomment the code below to restore support for Redux Saga
    // Dev Tools once it supports redux-saga version 1.x.x
    // if (window.__SAGA_MONITOR_EXTENSION__)
    //   reduxSagaMonitorOptions = {
    //     sagaMonitor: window.__SAGA_MONITOR_EXTENSION__,
    //   };
    /* eslint-enable */
  }

  const sagaMiddleware = createSagaMiddleware(reduxSagaMonitorOptions);

  // 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), logger];

  const enhancers = [applyMiddleware(...middlewares)];

  const store = createStore(rootReducer, initialState, composeEnhancers(...enhancers));

  // Extensions
  store.runSaga = sagaMiddleware.run;

  store.runSaga(sagas);

  return store;
}
Example #2
Source File: store.js    From allay-fe with MIT License 6 votes vote down vote up
store = createStore(
	rootReducer,
	composeEnhancers(
		applyMiddleware(
			thunk
			//, logger
		)
	)
)
Example #3
Source File: Login.spec.js    From carpal-fe with MIT License 6 votes vote down vote up
function renderWithRedux(
    ui,
    { store = createStore(reducer, applyMiddleware(thunk)) } = {}
) {
    return {
        ...render(<Provider store={store}>{<Router>{ui}</Router>}</Provider>),
        store
    };
}
Example #4
Source File: Activity.test.js    From quake-fe with MIT License 6 votes vote down vote up
describe("Activity.js Tests", () => {
  const store = createStore(reducers, applyMiddleware(thunk));

  it("should render...", () => {
    rtl.render(
      <Provider store={store}>
        <Activity />
      </Provider>
    );
  });
});
Example #5
Source File: store.js    From resumeker-fe with MIT License 6 votes vote down vote up
export default function store(preloadedState) {
  const store = createStore(
    rootReducer(history),
    preloadedState,
    applyMiddleware(routerMiddleware(history), thunk, logger)
  );

  return store;
}
Example #6
Source File: store.js    From react-firebase-admin with MIT License 6 votes vote down vote up
configureStore = initialState => {
  const middlewares = [];

  const composeEnhancers =
    (process.env.NODE_ENV === 'development'
      ? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
      : null) || compose;

  middlewares.push(applyMiddleware(thunk));

  const store = createStore(
    rootReducer,
    initialState,
    composeEnhancers(...middlewares)
  );

  store.dispatch(verifyAuth());

  const persistor = persistStore(store);

  return { store, persistor };
}
Example #7
Source File: store.js    From Designer-Client with GNU General Public License v3.0 6 votes vote down vote up
store = () => {
  let store = createStore(
    persistedReducer,
    composeWithDevTools(
      applyMiddleware(
        axiosMiddleware(axiosClient),
        thunkMiddleware,
        loggerMiddleware
      ),
    ),
  );
  let persistor = persistStore(store);

  return { store, persistor }
}
Example #8
Source File: index.js    From defizap-frontend with GNU General Public License v2.0 6 votes vote down vote up
configureStore = (initialState, history) => {
  const middlewares = [thunk, routerMiddleware(history)];
  const storeEnhancers = [];

  const isDev = process.env.NODE_ENV !== 'production';
  if (isDev) {
    // allow devs to use their own plugged in browser redux dev tool instead of the builtin component
    const devTools = DevTools();
    const devToolsEnhancer = window.__REDUX_DEVTOOLS_EXTENSION__
      ? window.__REDUX_DEVTOOLS_EXTENSION__()
      : devTools.instrument();
    storeEnhancers.push(devToolsEnhancer);
  }

  const middlewareEnhancer = applyMiddleware(...middlewares);
  storeEnhancers.unshift(middlewareEnhancer);

  const store = createStore(
    rootReducer(history),
    initialState,
    compose(...storeEnhancers)
  );

  if (isDev && module.hot && module.hot.accept) {
    module.hot.accept('../reducers', () => {
      const nextRootReducer = lazy(() => import('../reducers'));
      store.replaceReducer(nextRootReducer);
    });
  }
  return store;
}
Example #9
Source File: index.js    From ChronoFactorem with GNU General Public License v3.0 6 votes vote down vote up
customMiddleware = composeWithDevTools(
  applyMiddleware(
    getSelectedCourseMiddleware,
    checkClashOrDeleteMiddleWare,
    checkSectionSwapMiddleware,
    checkLunchHourMiddleware,
    addSectionMiddleware,
    deleteSectionMiddleware,
    saveTTMiddleware,
    closeDialogMiddleware,
    thunk
  )
)
Example #10
Source File: index.js    From Spoke with MIT License 6 votes vote down vote up
constructor(history, initialState = {}) {
    const reducer = combineReducers({
      ...reducers,
      apollo: ApolloClientSingleton.reducer(),
      routing: routerReducer
    });

    this.data = createStore(
      reducer,
      initialState,
      compose(
        applyMiddleware(
          routerMiddleware(history),
          ApolloClientSingleton.middleware(),
          ReduxThunk.withExtraArgument(ApolloClientSingleton)
        ),
        typeof window === "object" &&
          typeof window.devToolsExtension !== "undefined"
          ? window.devToolsExtension()
          : f => f
      )
    );
  }
Example #11
Source File: store.js    From OSC-Legal with MIT License 6 votes vote down vote up
export default function configureStore(initialState) {
  // const epicMiddleware = createEpicMiddleware(rootEpic);

  const bundle = compose(applyMiddleware(thunkMiddleware));
  const createStoreWithMiddleware = bundle(createStore);
  const store = createStoreWithMiddleware(
    reducers,
    initialState,
    window.devToolsExtension ? window.devToolsExtension() : f => f
  );

  return store;
}
Example #12
Source File: configureStore.js    From HexactaLabs-NetCore_React-Initial with Apache License 2.0 6 votes vote down vote up
export default function configureStore(history, initialState) {
  const reducers = {
    form: formReducer,
    router: connectRouter(history),
    auth,
    home,
    provider,
    store
  };

  const middleware = [thunk, routerMiddleware(history)];

  const enhancers = [];
  // eslint-disable-next-line no-undef
  const isDevelopment = process.env.NODE_ENV === "development";

  if (
    isDevelopment &&
    typeof window !== "undefined" &&
    window.devToolsExtension
  ) {
    enhancers.push(window.devToolsExtension());
  }

  const rootReducer = combineReducers(reducers);

  return createStore(
    rootReducer,
    initialState,
    compose(
      applyMiddleware(...middleware),
      ...enhancers
    )
  );
}
Example #13
Source File: configureStore.js    From flame-coach-web with MIT License 6 votes vote down vote up
createOwnStore = (reducers) => {
  const middlewares = [thunkMiddleware, logger];
  const middlewareEnchancer = applyMiddleware(...middlewares);

  const enchancers = [middlewareEnchancer];
  const composedEnchancers = composeWithDevTools(...enchancers);

  return createStore(reducers, undefined, composedEnchancers);
}
Example #14
Source File: createStore.js    From volt-mx-tutorials with Apache License 2.0 6 votes vote down vote up
initStore = (initialState = {}) => {
  let middlewares = createMiddlewares();

  return createStore(
    rootReducer,
    initialState,
    composeEnhancers(applyMiddleware(...middlewares))
  );
}
Example #15
Source File: store.js    From IBM-db2-blockchain-insurance-application with Apache License 2.0 6 votes vote down vote up
export default function configStore(initialState) {
  return createStore(
    rootReducer,
    initialState,
    applyMiddleware(
      ReduxThunk
    )
  );
}
Example #16
Source File: configureStore.js    From dexwebapp with Apache License 2.0 6 votes vote down vote up
// Setting preloadedState is still behind setting initState in each reducer
export default function configureStore(preloadedState) {
  const composeEnhancer =
    window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;

  const store = createStore(
    createRootReducer(history),
    preloadedState,
    composeEnhancer(
      applyMiddleware(
        thunk,
        routerMiddleware(history),
        trackingMiddleware(tracker)
      )
    )
  );

  // Hot reloading
  if (module.hot) {
    // Enable Webpack hot module replacement for reducers
    module.hot.accept('./reducers', () => {
      store.replaceReducer(createRootReducer(history));
    });
  }

  return store;
}
Example #17
Source File: configureStore.js    From HexactaLabs-NetCore_React-Level2 with Apache License 2.0 6 votes vote down vote up
export default function configureStore(history, initialState) {
  const reducers = {
    form: formReducer,
    router: connectRouter(history),
    auth,
    home,
    provider,
    productType,
    store
  };

  const middleware = [thunk, routerMiddleware(history)];

  const enhancers = [];
  // eslint-disable-next-line no-undef
  const isDevelopment = process.env.NODE_ENV === "development";

  if (
    isDevelopment &&
    typeof window !== "undefined" &&
    window.devToolsExtension
  ) {
    enhancers.push(window.devToolsExtension());
  }

  const rootReducer = combineReducers(reducers);

  return createStore(
    rootReducer,
    initialState,
    compose(
      applyMiddleware(...middleware),
      ...enhancers
    )
  );
}
Example #18
Source File: index.js    From WebApp with MIT License 6 votes vote down vote up
ReactDOM.render(
  <Provider store={createStore(reducers, applyMiddleware(thunk, logger))}>
    <MuiThemeProvider theme={Theme}>
      <IntlProvider locale="en" messages={messagesEn}>
        <App/>
      </IntlProvider>
    </MuiThemeProvider>
  </Provider>,
  document.querySelector('#root')
)
Example #19
Source File: store.js    From NextcloudDuplicateFinder with GNU Affero General Public License v3.0 6 votes vote down vote up
store = createStore(
  persistedReducer,
  undefined,
  composeWithDevTools(
    applyMiddleware(
      sagaMiddleware
    )
  )
)
Example #20
Source File: configureStore.js    From doraemon with GNU General Public License v3.0 6 votes vote down vote up
export default function configure(initialState) {
  // console.log('initialState', initialState)
  const create = window.devToolsExtension
    ? window.devToolsExtension()(createStore)
    : createStore

  const createStoreWithMiddleware = applyMiddleware(
    reduxRouterMiddleware,
    thunkMiddleware,
    logger,
    // router,
  )(create)

  const store = createStoreWithMiddleware(rootReducer, initialState)

  if (module.hot) {
    module.hot.accept('../reducers', () => {
      store.replaceReducer(nextReducer)
    })
  }

  return store
}
Example #21
Source File: configureStore.js    From sampo-ui with MIT License 6 votes vote down vote up
export default function configureStore (preloadedState) {
  const epicMiddleware = createEpicMiddleware()
  const middlewares = [epicMiddleware]

  // https://github.com/zalmoxisus/redux-devtools-extension#11-basic-store
  const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose

  const composedEnhancers = composeEnhancers(
    applyMiddleware(...middlewares)
    // other store enhancers could be added here
  )

  const store = createStore(reducer, preloadedState, composedEnhancers)

  epicMiddleware.run(rootEpic)

  bindActionCreators(toastrActions, store.dispatch)

  return store
}
Example #22
Source File: store.js    From tomato-food-delivery with Apache License 2.0 6 votes vote down vote up
store = createStore(
  rootReducer,
  initialState,
  compose(
    applyMiddleware(...middleware),
    (window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ &&
      window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__()) ||
      compose
  )
)
Example #23
Source File: store.js    From Conduit-Cypress with MIT License 6 votes vote down vote up
getMiddleware = () => {
  // we only collect code coverage in non-production environment
  // thus "IF" branch will never get hit
  /* istanbul ignore if */
  if (process.env.NODE_ENV === 'production') {
    return applyMiddleware(
      myRouterMiddleware,
      promiseMiddleware,
      localStorageMiddleware
    )
  } else {
    // Enable additional logging in non-production environments.
    return applyMiddleware(
      myRouterMiddleware,
      promiseMiddleware,
      localStorageMiddleware,
      createLogger()
    )
  }
}
Example #24
Source File: index.js    From scalable-form-platform with MIT License 6 votes vote down vote up
constructor(...args) {
        super(...args);
        this.state = {};
        this.namespace = util.getRandomString(8);
        this.store = createStore(
          combineReducers(xformBuilderReducer),
          compose(applyMiddleware(thunkMiddleware))
        );
    }
Example #25
Source File: configureStore.dev.js    From Lambda with MIT License 6 votes vote down vote up
export default function configureStore(history) {
  const composeEnhancers =
    window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
  const enhancer = composeEnhancers(
    applyMiddleware(thunk, routerMiddleware(history))
  );
  const store = createStore(root, enhancer);

  if (module.hot) {
    // Enable Webpack hot module replacement for reducers
    module.hot.accept("./rootReducer", () => {
      const nextRootReducer = require("./rootReducer").default;
      store.replaceReducer(nextRootReducer);
    });
  }

  return store;
}
Example #26
Source File: configureStore.dev.js    From Learning-Redux with MIT License 6 votes vote down vote up
configureStore = (preloadedState) => {
  const store = createStore(
    rootReducer,
    preloadedState,
    compose(applyMiddleware(thunk, api, createLogger()), DevTools.instrument())
  );

  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 #27
Source File: configureStore.js    From websocket-demo with MIT License 6 votes vote down vote up
export default function configureStore(preloadedState) {
  const middlewares = [thunkMiddleware];
  const middlewareEnhancer = applyMiddleware(...middlewares);

  const enhancers = [middlewareEnhancer];
  const composedEnhancers = compose(...enhancers);

  const store = createStore(reducer, preloadedState, composedEnhancers);

  return store;
}
Example #28
Source File: configureStore.js    From strapi-plugin-config-sync with MIT License 6 votes vote down vote up
configureStore = () => {
  const initialStoreState = Map();

  const enhancers = [];
  const middlewares = [
    thunkMiddleware,
  ];

  let devtools;

  if (__DEBUG__) {
    devtools = (
      typeof window !== 'undefined'
      && typeof window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ === 'function'
      && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({ actionsBlacklist: [] })
    );

    if (devtools) {
      console.info('[setup] ✓ Enabling Redux DevTools Extension');
    }
  }

  const composedEnhancers = devtools || compose;
  const storeEnhancers = composedEnhancers(
    applyMiddleware(...middlewares),
    ...enhancers,
  );

  const store = createStore(
    rootReducer,
    initialStoreState,
    storeEnhancers,
  );

  return store;
}
Example #29
Source File: configureStore.dev.js    From djact with MIT License 6 votes vote down vote up
export default function configureStore(initialState) {
  const composeEnhancers =
    window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose; // add support for Redux dev tools

  return createStore(
    rootReducer,
    initialState,
    composeEnhancers(applyMiddleware(thunk, reduxImmutableStateInvariant()))
  );
}