我有功能缩减器,例如:
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中创建子状态,它使用我的特性缩减器的子集。例如:
应用状态:
{
bananaState: namedReducer('banana')(/* here chaining together CreateReducer and LoadReducer */),
appleState: namedReducer('apple')(/* here chaining together LoadReducer, DeleteReducer */)
}
当我发出一个动作时
{name: 'banana', type: 'Load'}
它会碰到香蕉减速机。这方面有什么模式或建议吗?我试过了
compose
还有
combineReducers
但是没有运气。我错过了什么。是否有将功能链接在一起的工具。
非常感谢。
当做
塔马斯