在 Angular 中使用 ngrx 进行状态管理时控制台记录状态数据
Console log the state data when using ngrx for State Management in Angular
任何人都可以建议在 angular 应用程序中使用 ngrx 进行状态管理时如何控制台记录状态。我已经浏览过 ngrx-store-logger 但文档并不清楚如何创建 meta-reducer 和使用这个库。
这可以使用元减速器来完成,如 NgRx example app
所示
export function logger(reducer: ActionReducer<State>): ActionReducer<State> {
return (state: State, action: any): any => {
const result = reducer(state, action);
console.groupCollapsed(action.type);
console.log('prev state', state);
console.log('action', action);
console.log('next state', result);
console.groupEnd();
return result;
};
}
/**
* By default, @ngrx/store uses combineReducers with the reducer map to compose
* the root meta-reducer. To add more meta-reducers, provide an array of meta-reducers
* that will be composed to form the root meta-reducer.
*/
export const metaReducers: MetaReducer<State>[] = !environment.production
? [logger, storeFreeze]
: [];
任何人都可以建议在 angular 应用程序中使用 ngrx 进行状态管理时如何控制台记录状态。我已经浏览过 ngrx-store-logger 但文档并不清楚如何创建 meta-reducer 和使用这个库。
这可以使用元减速器来完成,如 NgRx example app
所示export function logger(reducer: ActionReducer<State>): ActionReducer<State> {
return (state: State, action: any): any => {
const result = reducer(state, action);
console.groupCollapsed(action.type);
console.log('prev state', state);
console.log('action', action);
console.log('next state', result);
console.groupEnd();
return result;
};
}
/**
* By default, @ngrx/store uses combineReducers with the reducer map to compose
* the root meta-reducer. To add more meta-reducers, provide an array of meta-reducers
* that will be composed to form the root meta-reducer.
*/
export const metaReducers: MetaReducer<State>[] = !environment.production
? [logger, storeFreeze]
: [];