本文整理汇总了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;
};
示例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,
);
}
示例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;
};
示例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)
}
}
}
示例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]);
}
示例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)));
}
}
示例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;
}
示例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;
};
示例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;
}
示例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 };
}