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


TypeScript redux-logger.createLogger函數代碼示例

本文整理匯總了TypeScript中redux-logger.createLogger函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript createLogger函數的具體用法?TypeScript createLogger怎麽用?TypeScript createLogger使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了createLogger函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: loadState

const configureStore = () => {
  const persistedState = loadState();

  let middleware = [thunkMiddleware];
  let newMiddleware = [];
  if (process.env.NODE_ENV !== 'production') {
    const loggerMiddleware = createLogger();
    newMiddleware = [...middleware, loggerMiddleware];
  } else {
    newMiddleware = middleware;
  }

  const store = createStore<AppState>(
    appReducer,
    // persistedState,
    applyMiddleware(...newMiddleware)
  );

  let token = getToken();
  if (token !== null) {
    store.dispatch(receiveTokenActionCreator(token.user, token));
  }

  store.subscribe(_.throttle(() => {
    saveState(store.getState());
  },                         1000));

  return store;
};
開發者ID:ttsvetanov,項目名稱:polyaxon,代碼行數:29,代碼來源:configureStore.ts

示例2: constructor

  constructor(
    private ngRedux: NgRedux<IAppState>,
    private devTool: DevToolsExtension,
    private rootEpic: RootEpic,
    private router: Router,
  ) {
    const middleware = [
      createEpicMiddleware(this.rootEpic.combineAll()),
      createLogger(),
    ];

    const reducer = compose(
      mergePersistedState()
    )(rootReducer);

    const storage = compose(
      filter('auth')
    )(adapter(window.localStorage));

    const enhancers = [
      persistState(storage, 'fyibn/store'),
    ];

    if (devTool.isEnabled()) {
      enhancers.push(devTool.enhancer());
    }

    this.ngRedux.configureStore(
      reducer,
      {} as IAppState,
      middleware,
      enhancers,
    );
  }
開發者ID:pusherman,項目名稱:fyibn-ui,代碼行數:34,代碼來源:app.component.ts

示例3: 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

示例4: 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

示例5: constructor

  constructor(
    private ngRedux: NgRedux<IAppState>,
    private devTool: DevToolsExtension) {

    // configure the store here, this is where the enhancers are set
    this.ngRedux.configureStore(rootReducer, {},
      isDevMode() ? [createLogger({ collapsed: true })] : [],
      isDevMode() && devTool.isEnabled() ? [...enhancers, devTool.enhancer()] : [...enhancers]);
  }
開發者ID:projectSHAI,項目名稱:expressgular2,代碼行數:9,代碼來源:redux.module.ts

示例6: configureStore

export function configureStore() {
  const composeEnhancers = (window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;

  if (process.env.NODE_ENV !== 'production') {
    // DEV builds we had the logger middleware
    store = createStore(rootReducer, {}, composeEnhancers(applyMiddleware(thunk, createLogger())));
  } else {
    store = createStore(rootReducer, {}, composeEnhancers(applyMiddleware(thunk)));
  }
}
開發者ID:ArcticSnowman,項目名稱:grafana,代碼行數:10,代碼來源:configureStore.ts

示例7: logger

export function logger() {
  const craftedLogger = createLogger({
    // predicate: (getState, action) => action.type.includes('COMM'),
    stateTransformer: (state: any) =>
      Object.keys(state).reduce(
        (prev, key) =>
          Object.assign({}, prev, {
            [key]: isCollection(state[key]) ? state[key].toJS() : state[key]
          }),
        {}
      )
  });
  return craftedLogger;
}
開發者ID:kelleyblackmore,項目名稱:nteract,代碼行數:14,代碼來源:middlewares.ts

示例8: createLogger

export const createAppStore = (initialState?: ApplicationStore): Store<ApplicationStore> => {
  if (appStore) {
    return appStore;
  }

  const middlewares = [
    thunk,
    createLogger(),
  ];

  appStore = createStore<ApplicationStore>(rootReducer, initialState, compose(
    applyMiddleware(...middlewares),
  ));
  return appStore;
};
開發者ID:jmptr,項目名稱:lost-sloth,代碼行數:15,代碼來源:store.ts

示例9: initializeStore

export default function initializeStore(
    context: ThunkContext,
    save: (state: Object) => Promise<void>,
    restore: (keys: string[]) => Promise<any>
): Store<State, Event> {
    const middlewares: Middleware<State, Event>[] = [
        errorHandlingMiddleware((error, { dispatch }) => {
            const errorString = (error + '') || 'Unknown error occured';

            dispatch(sendNotification(
                errorString,
                'negative',
                0
            ));
        }),
        thunkMiddleware(context),
        saveStateMiddleware(save, 1000)
    ];

    if (process.env.NODE_ENV !== 'production') {
        middlewares.push(reduxMiddleware(createLogger({ duration: true })));
    }

    const store = applyMiddlewares(createStore(reducer, initialState), middlewares);

    restore(Object.keys(initialState)).then((partialState) => {
        const state = {
            ...mergeState(store.getState(), partialState),
            version: packageJson.version
        };

        store.replaceState(state);

        store.dispatch({
            type: 'APPLICATION_INITIALIZED'
        });
    });

    return store;
}
開發者ID:emonkak,項目名稱:feedpon,代碼行數:40,代碼來源:initializeStore.ts

示例10: configureStore

export default function configureStore(defaultState?: State) {
  const middlewares = [ravenMiddleware, thunk, requestsMiddleware];

  if (process.env.NODE_ENV === 'development') {
    /* eslint-disable */
    const { createLogger } = require('redux-logger');
    /* eslint-enable */
    const logger = createLogger({
      level: 'info',
      collapsed: true,
      duration: true,
      diff: true,
      // Avoid diffing actions that insert a lot of stuff into the state to prevent console from lagging
      diffPredicate: (getState: GetState, action: FSA) =>
        !action.type.startsWith('FETCH_MODULE_LIST') && !action.type.startsWith('persist/'),
    });
    middlewares.push(logger);
  }

  const storeEnhancer = applyMiddleware(...middlewares);

  const store: Store<State, any> = createStore(
    rootReducer,
    // @ts-ignore TODO: Figure out why undefined isn't accepted
    defaultState,
    composeEnhancers(storeEnhancer),
  );

  if (module.hot) {
    // Enable webpack hot module replacement for reducers
    module.hot.accept('../reducers', () => store.replaceReducer(rootReducer));
  }

  const persistor = persistStore(store);
  return { persistor, store };
}
開發者ID:nusmodifications,項目名稱:nusmods,代碼行數:36,代碼來源:configure-store.ts


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