本文整理汇总了TypeScript中redux.compose函数的典型用法代码示例。如果您正苦于以下问题:TypeScript compose函数的具体用法?TypeScript compose怎么用?TypeScript compose使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了compose函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: createAdminUIStore
export function createAdminUIStore() {
const sagaMiddleware = createSagaMiddleware();
const s: Store<AdminUIState> = createStore(
combineReducers<AdminUIState>({
cachedData: apiReducersReducer,
hover: hoverReducer,
localSettings: localSettingsReducer,
metrics: metricsReducer,
queryManager: queryManagerReducer,
routing: routerReducer,
timewindow: timeWindowReducer,
uiData: uiDataReducer,
login: loginReducer,
}),
compose(
applyMiddleware(thunk, sagaMiddleware, routerMiddleware(hashHistory)),
// Support for redux dev tools
// https://chrome.google.com/webstore/detail/redux-devtools/lmhkpmbekcpmknklioeibfkpmmfibljd
(window as any).devToolsExtension ? (window as any).devToolsExtension({
// TODO(maxlang): implement {,de}serializeAction.
// TODO(maxlang): implement deserializeState.
serializeState: (_key: string, value: any): Object => {
if (value && value.toRaw) {
return value.toRaw();
}
return value;
},
}) : _.identity,
) as GenericStoreEnhancer,
);
sagaMiddleware.run(queryMetricsSaga);
return s;
}
示例2: createSagaMiddleware
export const configureStore = () => {
const sagaMiddleware = createSagaMiddleware()
const logger = createLogger()
const store = createStore(
persistReducer({ key: 'reversi', storage, whitelist: ['history'] }, reducer),
compose(
applyMiddleware(sagaMiddleware, logger),
getDevtools()
)
)
const persistor = persistStore(store)
if (module.hot) {
module.hot.accept('./reducer', () => {
store.replaceReducer(require('./reducer').default)
})
}
return {
store,
persistor,
runSaga: sagaMiddleware.run,
close () {
store.dispatch(END as any)
}
}
}
示例3: getStore
export default function getStore(initialState?:any){
const enhancer = compose
( applyMiddleware
( reduxImmutableStateInvariant()
, thunk
)
//, getDevTools()
, DevTools.instrument()
, persistState(getDebugSessionKey()
)
);
const store = createStore
( rootReducer
, initialState
, enhancer
);
if(module.hot){
module.hot.accept
( '../actions'
, () => store.replaceReducer(require('../actions').reducer)
);
}
return store;
}
示例4: createApolloStore
export function createApolloStore({
reduxRootKey = 'apollo',
initialState,
config = {},
reportCrashes,
}: {
reduxRootKey?: string,
initialState?: any,
config?: ApolloReducerConfig,
reportCrashes?: boolean,
} = {}): ApolloStore {
const enhancers = [];
if (reportCrashes === undefined) {
reportCrashes = true;
}
if (typeof window !== 'undefined') {
const anyWindow = window as any;
if (anyWindow.devToolsExtension) {
enhancers.push(anyWindow.devToolsExtension());
}
}
if (reportCrashes) {
enhancers.push(applyMiddleware(crashReporter));
}
return createStore(
combineReducers({ [reduxRootKey]: createApolloReducer(config) }),
initialState,
compose(...enhancers) as () => any // XXX see why this type fails
);
}
示例5: return
return () => {
// Figure out reducers
let reducersToUse = reducers;
if (typeof reducersToUse === "object") {
// it's not a single reducer so we need to combine the reducers on the object properties
reducersToUse = combineReducers(reducersToUse);
}
let thunkMiddlewareToUse = thunkMiddleware;
// Fix for import issues
if (thunkMiddlewareToUse && thunkMiddlewareToUse["default"]) {
thunkMiddlewareToUse = thunkMiddlewareToUse["default"];
}
const middlewareEnhancer = applyMiddleware(thunkMiddlewareToUse,...additionalMiddlewares);
const enhancers = compose(middlewareEnhancer, applyDevTools(debug));
const createStoreWithEnhancers = enhancers(createStore);
const reduxAppStore = createStoreWithEnhancers(reducersToUse);
// const reduxAppStore = createStore(reducers, undefined, enhancers); // new API (not typed yet)
return new AppStore(reduxAppStore);
}
示例6: createStore
export const createAdminUIStore = () => createStore(
combineReducers<AdminUIState>({
routing: routerReducer,
ui: uiReducer,
uiData: uiDataReducer,
metrics: metricsReducer,
timewindow: timeWindowReducer,
cachedData: apiReducersReducer,
}),
compose(
applyMiddleware(thunk),
// Support for redux dev tools
// https://chrome.google.com/webstore/detail/redux-devtools/lmhkpmbekcpmknklioeibfkpmmfibljd
(window as any).devToolsExtension ? (window as any).devToolsExtension({
// TODO(maxlang): implement {,de}serializeAction.
// TODO(maxlang): implement deserializeState.
serializeState: (key: string, value: any): Object => {
if (value && value.toRaw) {
return value.toRaw();
}
return value;
},
}) : _.identity
) as GenericStoreEnhancer
);
示例7: default
export default (history: History, dsn: string) => {
const sagaMiddleware: SagaMiddleware<{}> = createSagaMiddleware();
let middlewares: Middleware[] = [];
if (process.env.NODE_ENV !== 'production') {
middlewares = [
createLogger(),
];
}
Raven.config(dsn).install();
const devtools: any = process.env.NODE_ENV !== 'production' && (window as any)._REDUX_DEVTOOLS_EXTENSION__ ?
(window as any)._REDUX_DEVTOOLS_EXTENSION__() : (f: any) => f;
const store = createStore(
createRootReducer(history),
compose(
applyMiddleware(
routerMiddleware(history),
googleAnalytics,
sagaMiddleware,
createRavenMiddleware(Raven, {}),
...middlewares,
),
devtools,
),
);
sagaMiddleware.run(rootSaga);
return store;
};
示例8: configureStore
export function configureStore(history, initialState?: any): Redux.Store {
let middlewares: any[] = [
routerMiddleware(history),
thunk
];
/** Add Only Dev. Middlewares */
if (appConfig.env !== 'production' && process.env.BROWSER) {
const logger = createLogger();
middlewares.push(logger);
}
const finalCreateStore = compose(
applyMiddleware(...middlewares),
appConfig.env === 'development' &&
typeof window === 'object' &&
typeof window.devToolsExtension !== 'undefined'
? window.devToolsExtension() : f => f
)(createStore);
const store: Redux.Store = finalCreateStore(rootReducer, initialState);
if (appConfig.env === 'development' && (module as any).hot) {
(module as any).hot.accept('./reducers', () => {
store.replaceReducer((require('./reducers')));
});
}
return store;
}
示例9: configureStore
function configureStore(initialState) {
const store = compose(
_getMiddleware()
)(createStore)(rootReducer, initialState);
_enableHotLoader(store);
return store;
}
示例10: default
export default (reducer: Redux.Reducer = appReducer): Redux.Store => {
let createStoreWithMiddleware = compose(
applyMiddleware(thunkMiddleware, logger),
window['devToolsExtension'] ? window['devToolsExtension']() : f => f
)(createStore);
return createStoreWithMiddleware(reducer);
};