當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript redux.compose函數代碼示例

本文整理匯總了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;
}
開發者ID:a6802739,項目名稱:cockroach,代碼行數:35,代碼來源:state.ts

示例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)
    }
  }
}
開發者ID:DanSnow,項目名稱:react-reversi,代碼行數:27,代碼來源:store.ts

示例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;
}
開發者ID:Xananax,項目名稱:typescript-hmr-boilerplate,代碼行數:28,代碼來源:configureStore.dev.ts

示例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
  );
}
開發者ID:JohnWelle,項目名稱:apollo-client,代碼行數:34,代碼來源:store.ts

示例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);

    }
開發者ID:micha149,項目名稱:angular2-redux,代碼行數:25,代碼來源:app-store-factory.ts

示例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
);
開發者ID:martinpinto,項目名稱:cockroach,代碼行數:25,代碼來源:state.ts

示例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;
};
開發者ID:8398a7,項目名稱:8398a7.github.io,代碼行數:27,代碼來源:store.ts

示例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;
}
開發者ID:MagiCarbon,項目名稱:vortigern,代碼行數:31,代碼來源:store.ts

示例9: configureStore

function configureStore(initialState) {
  const store = compose(
    _getMiddleware()
  )(createStore)(rootReducer, initialState);

  _enableHotLoader(store);
  return store;
}
開發者ID:nimatra,項目名稱:GithubIssueViewer,代碼行數:8,代碼來源:configure-store.ts

示例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);
};
開發者ID:sambou,項目名稱:ng-redux-example,代碼行數:8,代碼來源:index.ts


注:本文中的redux.compose函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。