redux#applyMiddleware TypeScript 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: store.ts From rn-clean-architecture-template with MIT License | 6 votes |
export function configureStore(): StoreContainer {
const reducerManager = createReducerManager({
authentication: authenticationReducer,
configuration: configurationReducer,
});
const {rootEpic, epicMiddleware, epic$, addEpic} = createEpicManager(
{},
authenticationEpic,
configurationEpic,
);
// Create a store with the root reducer function being the one exposed by the manager.
const action$ = new BehaviorSubject<Action>({type: 'init'});
const reducer = (
state: RootStoreState | undefined,
action: Action<string>,
) => {
action$.next(action);
return reducerManager.reduce(state, action);
};
const store = createStore<RootStoreState, Action<string>, any, any>(
reducer,
applyMiddleware(epicMiddleware),
);
epicMiddleware.run(rootEpic);
// Optional: Put the reducer manager on the store so it is easily accessible
return {
reducerManager,
store,
epic$,
action$,
addEpic,
};
}
Example #2
Source File: devStoreConfig.ts From react-app-architecture with Apache License 2.0 | 6 votes |
devStoreConfig = (preloadedState: Partial<RootState>): Store => {
const store = createStore(
rootReducer,
preloadedState,
applyMiddleware(thunk, logger, crashReporter),
);
// @ts-ignore
if (module.hot) {
// Enable Webpack hot module replacement for reducers
// @ts-ignore
module.hot.accept('../reducers', () => {
const nextRootReducer = require('../reducers');
store.replaceReducer(nextRootReducer);
});
}
return store;
}
Example #3
Source File: createStore.ts From diagram-maker with Apache License 2.0 | 6 votes |
export default function createStore<NodeType, EdgeType>(
initialData?: DiagramMakerData<NodeType, EdgeType>,
consumerRootReducer?: Reducer<DiagramMakerData<NodeType, EdgeType>, DiagramMakerAction<NodeType, EdgeType>>,
consumerEnhancer?: StoreEnhancer,
actionInterceptor?: ActionInterceptor<NodeType, EdgeType>,
): Store<DiagramMakerData<NodeType, EdgeType>> {
const interceptorMiddleware = applyMiddleware(createInterceptorMiddleware(actionInterceptor));
const undoMiddleware = applyMiddleware(getUndoMiddleware());
const middleware = compose(interceptorMiddleware, undoMiddleware);
const composedEnhancer = consumerEnhancer
? compose(middleware, consumerEnhancer)
: middleware;
/**
* FIXME: Due to this issue: https://github.com/Microsoft/TypeScript/issues/21592
* The below line needs an "any" typecast. It throws a type error for excessive
* stack depth otherwise. Also, note that due to the type signatures on the function
* declaration, type safety is lost within this method, but is retained everywhere else.
* Remove this when typescript fixes it.
*/
return reduxCreateStore(
sequenceReducers<DiagramMakerData<NodeType, EdgeType>, DiagramMakerAction<NodeType, EdgeType>>(
getRootReducer(),
layoutReducer,
consumerRootReducer,
),
initialData as any,
composedEnhancer,
);
}
Example #4
Source File: configureStore.ts From che-dashboard-next with Eclipse Public License 2.0 | 6 votes |
export default function configureStore(history: History, initialState?: AppState): Store {
const middleware = [
thunk,
routerMiddleware(history)
];
const rootReducer = combineReducers({
...reducers,
router: connectRouter(history)
});
const enhancers: any[] = [];
const windowIfDefined = typeof window === 'undefined' ? null : window as any;
if (windowIfDefined && windowIfDefined.__REDUX_DEVTOOLS_EXTENSION__) {
enhancers.push(windowIfDefined.__REDUX_DEVTOOLS_EXTENSION__() as any);
}
return createStore(
rootReducer,
initialState,
compose(applyMiddleware(...middleware), ...enhancers)
);
}
Example #5
Source File: serverAdmin.ts From clearflask with Apache License 2.0 | 6 votes |
static createStoreMiddleware(isProject: boolean, name: string): StoreEnhancer {
var storeMiddleware = isProject
? applyMiddleware(thunk, reduxPromiseMiddleware, loadingBarMiddleware())
: applyMiddleware(thunk, reduxPromiseMiddleware);
if (!windowIso.isSsr) {
const composeEnhancers =
windowIso['__REDUX_DEVTOOLS_EXTENSION_COMPOSE__']
? windowIso['__REDUX_DEVTOOLS_EXTENSION_COMPOSE__']({
serialize: true,
name,
})
: compose;
storeMiddleware = composeEnhancers(storeMiddleware);
}
return storeMiddleware;
}
Example #6
Source File: store.ts From farrow with MIT License | 6 votes |
createReduxDevtoolsEnhancer = (devtools: boolean = true, name?: string, enableLogger = false) => {
const composeEnhancers =
// tslint:disable-next-line: strict-type-predicates
devtools && typeof window === 'object' && (window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
? (window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({
name,
})
: compose
const enhancer = enableLogger ? composeEnhancers(applyMiddleware(createLogger())) : composeEnhancers()
return enhancer
}
Example #7
Source File: configureStore.ts From firebase-tools-ui with Apache License 2.0 | 6 votes |
export default function configureStore(): Store<AppState> {
const composeEnhancers =
(window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
const sagaMiddleware = createSagaMiddleware();
const store = createStore(
rootReducer,
composeEnhancers(applyMiddleware(sagaMiddleware))
);
sagaMiddleware.run(rootSaga);
return store;
}
Example #8
Source File: App.ts From YoutubeLiveApp with MIT License | 6 votes |
constructor(app: App) {
this.app = app;
this.app.on("ready", this.onReady);
this.app.on("window-all-closed", this.onWindowAllClosed);
const packageJson = fs.readFileSync(packageJsonPath);
const packageJsonObject = JSON.parse(packageJson.toString("utf-8"));
this.version = packageJsonObject.version;
this.bouyomiChan = new BouyomiChan({
port: this.bouyomiChanPort,
});
const initialState = resumeData();
this.isAlwaysOnTop = !!initialState.isAlwaysOnTop;
this.serverRunning = !!initialState.fixedChatUrl;
const reducer = combineReducers({ app: createAppReducer(initialState), chat: createChatReducer(chatInitialState) });
const myCreateStore = compose(applyMiddleware(MainProcessMiddleware()))(createStore);
this.store = myCreateStore(reducer);
}
Example #9
Source File: index.ts From multisig-react with MIT License | 6 votes |
finalCreateStore = composeEnhancers( applyMiddleware( thunk, routerMiddleware(history), notificationsMiddleware, safeStorage, providerWatcher, addressBookMiddleware, currencyValuesStorageMiddleware, ), )
Example #10
Source File: index.ts From idena-pocket with MIT License | 6 votes |
store = (() => {
const store = createStore(
combineReducers({
router: connectRouter(history),
app: rootReducer(defaultState)
}),
compose(
applyMiddleware(routerMiddleware(history), ...middlewares),
...(process.env.NODE_ENV === 'development' && devtools
? [devtools()]
: [])
)
)
if ((module as any).hot) {
// Enable Webpack hot module replacement for reducers
;(module as any).hot.accept('../reducer', () => {
const nextRootReducer = require('../reducer')
store.replaceReducer(nextRootReducer)
})
}
return store
})()
Example #11
Source File: store.ts From polkabtc-ui with Apache License 2.0 | 6 votes |
configureStore = (): StoreState => {
const storeLogger = createLogger();
const state = loadState();
const store = createStore(rootReducer, state, applyMiddleware(storeLogger));
store.dispatch(initializeState(state));
store.subscribe(() => {
saveState(store.getState());
});
return store;
}
Example #12
Source File: create-store.ts From anthem with Apache License 2.0 | 6 votes |
configureStore = () => {
const reduxStore = createStore(
rootReducer,
composeWithDevTools(applyMiddleware(...middleware)),
);
// @ts-ignore
epicMiddleware.run(rootEpic);
return reduxStore;
}
Example #13
Source File: store.ts From foodie with MIT License | 6 votes |
configureStore = () => {
const store = createStore(
rootReducer,
reHydrateStore(),
composeEnhancers(applyMiddleware(...middlewares)),
);
sagaMiddleware.run(rootSaga);
return store;
}
Example #14
Source File: configureAppStore.ts From bob-extension with MIT License | 6 votes |
export default function configureAppStore() {
return createStore(
rootReducer,
process.env.NODE_ENV !== 'production'
? applyMiddleware(thunk, createLogger({
collapsed: (getState, action = {}) => [''].includes(action.type),
}))
: applyMiddleware(thunk),
);
}
Example #15
Source File: index.ts From fe-v5 with Apache License 2.0 | 6 votes |
start(): void {
let reducer = this.getReducer();
let sagas = this.getSagas();
let sagaMiddleware = createSagaMiddleware();
this.store = applyMiddleware(
createPromiseMiddleware(this),
sagaMiddleware,
)(createStore)(reducer);
sagas.forEach(sagaMiddleware.run);
}
Example #16
Source File: index.tsx From nouns-monorepo with GNU General Public License v3.0 | 6 votes |
export default function configureStore(preloadedState: PreloadedState<any>) {
const store = createStore(
createRootReducer(history), // root reducer with router state
preloadedState,
composeWithDevTools(
applyMiddleware(
routerMiddleware(history), // for dispatching history actions
// ... other middlewares ...
),
),
);
return store;
}
Example #17
Source File: App.store.tsx From tezos-academy with MIT License | 6 votes |
export function configureStore(preloadedState: any) {
const composeEnhancer = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({ trace: true, traceLimit: 25 })
: compose
const store: Store<State> = offline(storeOfflineConfig)(createStore)(
reducers(history) as any,
preloadedState,
composeEnhancer(
applyMiddleware(routerMiddleware(history)),
applyMiddleware(thunk),
applyMiddleware(reduxOfflineThunkMiddleware()),
),
)
return store
}
Example #18
Source File: configureStore.ts From tezos-link with Apache License 2.0 | 6 votes |
export function configureStore(preloadedState: any) {
const composeEnhancer = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose
const store = createStore(
rootReducer(history),
preloadedState,
composeEnhancer(applyMiddleware(routerMiddleware(history)), applyMiddleware(thunk))
)
return store
}
Example #19
Source File: configureStore.ts From orangehrm-os-mobile with GNU General Public License v3.0 | 6 votes |
configureStore = () => {
const preloadedState = {};
const store = createStore(
rootReducer,
preloadedState,
applyMiddleware(sagaMiddleware),
);
sagaMiddleware.run(rootSaga);
return store;
}
Example #20
Source File: configureStore.ts From querybook with Apache License 2.0 | 6 votes |
export default function configureStore(preloadedState?) {
const store = createStore(
rootReducer,
preloadedState,
composeEnhancers(
applyMiddleware(
// invariant(),
ReduxThunk
// loggerMiddleware
)
)
);
return store;
}
Example #21
Source File: store.ts From slice-machine with Apache License 2.0 | 6 votes |
export default function configureStore(
preloadedState: Partial<SliceMachineStoreType> = {}
): { store: Store<SliceMachineStoreType>; persistor: Persistor } {
const middlewares = [sagaMiddleware, routerMiddleware];
const enhancers = [applyMiddleware(...middlewares)];
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const composeEnhancers =
process.env.NODE_ENV !== "production" &&
typeof window === "object" &&
window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
: compose;
const rootReducer = createReducer();
const persistedReducer = persistReducer(persistConfig, rootReducer);
const store: Store<SliceMachineStoreType> = createStore(
persistedReducer,
preloadedState,
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-call
composeEnhancers(...enhancers)
);
const persistor = persistStore(store);
sagaMiddleware.run(rootSaga);
return { store, persistor };
}
Example #22
Source File: store.ts From rusty-chat with MIT License | 6 votes |
export default function configureStore(): any {
const sagaMiddleware = createSagaMiddleware();
const store = createStore(rootReducer, compose(applyMiddleware(routerMiddleware(history), sagaMiddleware)));
sagaMiddleware.run(apiSaga);
sagaMiddleware.run(userSaga);
sagaMiddleware.run(feedSaga);
return store;
}
Example #23
Source File: ide-renderer.tsx From kliveide with MIT License | 6 votes |
// ------------------------------------------------------------------------------
// --- Register the main services
// --- Register the store service
registerService(
STORE_SERVICE,
new KliveStore(
createStore(
rootReducer,
getInitialAppState(),
applyMiddleware(forwardToMainMiddleware)
)
)
);
Example #24
Source File: App.tsx From msteams-meetings-template with MIT License | 6 votes |
store = createStore( createRootReducer(hist), compose( applyMiddleware( routerMiddleware(hist), createAuthMiddleware(), createMeetingMiddleware() ) ) )
Example #25
Source File: configureStore.ts From mops-vida-pm-watchdog with MIT License | 6 votes |
configureStore = () =>
createStore(
createRootReducer(history),
undefined,
composeEnhancers(
applyMiddleware(
routerMiddleware(history), // connected-react-router
thunk as ThunkMiddleware<RootState>, // redux-thunk
),
),
)
Example #26
Source File: store.ts From hamagen-react-native with MIT License | 6 votes |
export default function () {
if (storeInstance) {
return storeInstance;
}
const configOffline = {
...offlineConfig,
rehydrate: true,
persistOptions: {
whitelist: []
}
};
storeInstance = createStore(reducers, {}, compose(applyMiddleware(thunkMiddleware), offline(configOffline)));
return storeInstance;
}
Example #27
Source File: index.ts From shippo with MIT License | 6 votes |
createStore = (compose?: (...middleware: Middleware[]) => StoreEnhancer) => {
compose = compose || applyMiddleware
const middleware: Array<Middleware> = [thunkMiddleware]
const stores = create(reducers, compose(...middleware))
const thunkDispatch: ThunkDispatch = (action) => stores.dispatch<any>(action)
const dispatch: Dispatch = (action) => stores.dispatch<any>(action)
const selector = <T>(selector: (store: IStores) => T) => selector(stores.getState())
return {
stores,
thunkDispatch,
dispatch,
selector,
}
}
Example #28
Source File: configureStore.ts From atorch-console with MIT License | 6 votes |
configureStore = () =>
createStore(
createRootReducer(history),
undefined,
composeEnhancers(
applyMiddleware(
routerMiddleware(history), // connected-react-router
thunk as ThunkMiddleware<RootState>, // redux-thunk
),
),
)
Example #29
Source File: store.ts From client with MIT License | 5 votes |
store = createStore(
rootReducer,
{},
process.env.NODE_ENV === 'development'
? composeWithDevTools(applyMiddleware(thunk))
: applyMiddleware(thunk)
)