我有功能缩减器,例如:LoadReducer
,DeleteReducer
和CreateReducer
。所有这些都只是简单的减速器。 (我还有一个名为namedReducer的更高级的减速器
export function namedReducer(reducerName: string) {
return (reducer: Function) => {
return function newReducer(state, action) {
const { name } = action;
const isInitializationCall = state === undefined;
const shouldRunWrappedReducer = reducerName === name || isInitializationCall;
return shouldRunWrappedReducer ? reducer(_.get(state, reducerName), action) : state;
};
};
}
我想在我的appstate中创建使用我的功能减少器子集的子状态。例如:
届时AppState:
{
bananaState: namedReducer('banana')(/* here chaining together CreateReducer and LoadReducer */),
appleState: namedReducer('apple')(/* here chaining together LoadReducer, DeleteReducer */)
}
当我发送一个动作{name: 'banana', type: 'Load'}
时,它会遇到香蕉LoadReducer。这个或任何建议有什么模式吗?我尝试了compose
和combineReducers
,但没有运气。我错过了什么是否有任何链接功能的工具。
非常感谢。
此致 的Tamas
答案 0 :(得分:0)