[Functional Programming ADT] Combine Multiple State ADT Based Redux Reducers
2024-10-21 13:42:07
Redux provides a convenient helper for combining many reducers called combineReducer
, but it focuses in on specific attributes on our state, making it incompatible with using the State ADT. We would like a way to avoid keeping all of our reducers in a single file and want the ability to still combine them in a manner that works with the State
ADT.
So we will put together our own helper that we also call combineReducers
, but explore how we can use the First
Monoid and mreduceMap
to get us all the power that the Redux helper provides, but setup for our unique needs. As a bonus we will get a sneak peak of the power of using the flip
combinator to create easy to read compositions without pesky argument juggling
// combineReducers :: [ Reducer ] -> Reducer
/*
export const combineReducers = reducers => action =>
mreduceMap(First, applyTo(action), reducers);
*/
// We take reducers first and action second, but we use action first, reducers second.
// It is good case to use flip
/*
export const combineReducers = flip(action =>
mreduceMap(First, applyTo(action))
);*/ // We can use compose to remove action param, applyTo will get action
// Then the return result will be passed into mreduceMap(First)
export const combineReducers = flip(
compose(
mreduceMap(First),
applyTo
)
);
最新文章
- RedHat Enterprise Linux 6.4 使用 Centos 6 的yum(转)
- jQuery对象与DOM对象之间的转换方法
- javascript中的链表结构—从链表中删除元素
- ce游戏内存修改器(Cheat Engine)
- 关于 ‘--exec’ 参数( find 命令)及介绍 ‘xargs ’命令区别(新版)
- CocoaPods 使用手册
- Android 应用开发性能优化完全分析
- Bzoj 2243: [SDOI2011]染色 树链剖分,LCT,动态树
- poj2007
- openresty nginx 安装过程记录
- hibou 主界面自己侧滑的定义
- 【Cocos2d-X游戏实战开发】捕鱼达人之单例对象的设计(二)
- USACO 3.3 Shopping Offers
- 15 Validation
- [Swift-2019力扣杯春季决赛]2. 按字典序排列最小的等效字符串
- SQL Sever 2008 R2版本添加Northwin数据库错误解决
- AHOI2019N省联考凉凉记
- java 面试题2
- java io系列12之 BufferedInputStream(缓冲输入流)的认知、源码和示例
- PTA寒假三