如何在 get Reducers(): ActionReducerMap<fromFeature.State> 中 return reducer 映射?
How to return a map of reducers in getReducers(): ActionReducerMap<fromFeature.State>?
我试图在通过 NgRx 功能模块组合状态时注入 功能缩减器。
import { NgModule, InjectionToken } from '@angular/core';
import { StoreModule, ActionReducerMap } from '@ngrx/store';
import * as fromFeature from './reducers';
export const FEATURE_REDUCER_TOKEN = new InjectionToken<ActionReducerMap<fromFeature.State>>('Feature Reducers');
这里我应该return做什么?
export function getReducers(): ActionReducerMap<fromFeature.State> {
// map of reducers
return {
};
}
我试过了
export function getReducers(): ActionReducerMap<fromFeature.State> {
// map of reducers
return {
reducerA: FeatureAReducer
};
}
但它给出错误对象文字可能只指定已知属性。
其余模块代码:
@NgModule({
imports: [
StoreModule.forFeature('feature', FEATURE_REDUCER_TOKEN),
],
providers: [
{
provide: FEATURE_REDUCER_TOKEN,
useFactory: getReducers
}
]
})
export class FeatureModule { }
我以为每个reducer,不管是root还是feature reducer,returns一个新的状态对象。但实际上并非如此。 feature reducer 的作用是,它 returns 仅更新状态的一部分。
we treat each reducer like a table in a database. This means our
top level state interface is just a map of keys to inner state types.
我试图在通过 NgRx 功能模块组合状态时注入 功能缩减器。
import { NgModule, InjectionToken } from '@angular/core';
import { StoreModule, ActionReducerMap } from '@ngrx/store';
import * as fromFeature from './reducers';
export const FEATURE_REDUCER_TOKEN = new InjectionToken<ActionReducerMap<fromFeature.State>>('Feature Reducers');
这里我应该return做什么?
export function getReducers(): ActionReducerMap<fromFeature.State> {
// map of reducers
return {
};
}
我试过了
export function getReducers(): ActionReducerMap<fromFeature.State> {
// map of reducers
return {
reducerA: FeatureAReducer
};
}
但它给出错误对象文字可能只指定已知属性。
其余模块代码:
@NgModule({
imports: [
StoreModule.forFeature('feature', FEATURE_REDUCER_TOKEN),
],
providers: [
{
provide: FEATURE_REDUCER_TOKEN,
useFactory: getReducers
}
]
})
export class FeatureModule { }
我以为每个reducer,不管是root还是feature reducer,returns一个新的状态对象。但实际上并非如此。 feature reducer 的作用是,它 returns 仅更新状态的一部分。
we treat each reducer like a table in a database. This means our top level state interface is just a map of keys to inner state types.