【发布时间】:2019-11-05 12:43:48
【问题描述】:
我有以下reducer函数:
reducers 的 first 参数是聚合值,second 参数是下一个值。下面的 reducer 函数对相同的 reaction 参数进行归约,但聚合了 state$ 值。每个 reducer 函数都会产生一个新的聚合值。
/**
* Applies all the reducers to create a state object.
*/
function reactionReducer(reaction: ReactionObject): ReactionObject {
let state$ = reactionDescriptionReducer({}, reaction);
state$ = reactionDisabledReducer(state$, reaction);
state$ = reactionIconReducer(state$, reaction);
state$ = reactionOrderReducer(state$, reaction);
state$ = reactionStyleReducer(state$, reaction);
state$ = reactionTitleReducer(state$, reaction);
state$ = reactionTooltipReducer(state$, reaction);
state$ = reactionVisibleReducer(state$, reaction);
return state$;
}
const state = reactionReducer(value);
上述方法有效,但该功能已修复,包含减速器列表。看来我应该可以用 RamdaJS 做这样的事情。
const state = R.????({}, value, [reactionDescriptionReducer
reactionDisabledReducer,
reactionIconReducer,
reactionOrderReducer,
reactionStyleReducer,
reactionTitleReducer,
reactionTooltipReducer,
reactionVisibleReducer]);
我是 RamdaJS 的新手,如果这是一个菜鸟问题,请原谅我。
如何仅使用 RamdaJS 执行一系列 reducer?
【问题讨论】:
-
您是否尝试使用
ap创建函数列表? -
查看
curry、flip、juxt、map和pipe
标签: javascript typescript functional-programming ramda.js