gpt4 book ai didi

ngrx - 如何在 getReducers() : ActionReducerMap 中返回 reducer 映射?

转载 作者:行者123 更新时间:2023-12-01 00:23:22 29 4
gpt4 key购买 nike

我正在尝试注入(inject) 特征 reducer 通过 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');
我应该在这里返回什么?
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,都会返回一个新的 state 对象。但实际上并没有。什么功能减少器,它只返回它更新的状态段。
来自 ngrx/platform/example-app :

we treat each reducer like a table in a database. This means ourtop level state interface is just a map of keys to inner state types.

关于ngrx - 如何在 getReducers() : ActionReducerMap<fromFeature. State> 中返回 reducer 映射?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46861256/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com