博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[Angular 2] Using a Reducer to Change an Object's Property Inside an Array
阅读量:7223 次
发布时间:2019-06-29

本文共 1354 字,大约阅读时间需要 4 分钟。

Reducers are also often used for changing a single property inside of other reducers. This lesson shows how a type can enter the people reducer, but then the people reducer can use a different type to call the clock reducer and get a value back.

 

So the logic is when we click on each person, the person's time will increase 3 hours:

 

First, add click event and yield the person object:

  • {
    {person.name}} is in {
    {person.time | date : 'jms'}}
... person$ = new Subject() .map( (person) => ({type: ADVANCE, payload: person}));

 

Then subscribe the person$, dispatch the action:

Observable.merge(            this.click$,            this.seconds$,            this.person$            )            .subscribe(store.dispatch.bind(store))

 

In the reducer, we change the person's time by using clock() reducer:

export const people = (state = defaultPeople, {type, payload}) => {    switch(type){        case ADVANCE:            return state.map( (person) => {                if(person === payload){                    return {                        name: person.name,                        time: clock(payload.time, {type: HOUR, payload: 3})                    }                }                return person;            });        default:            return state;    }};

 

 

------------

转载地址:http://rnxym.baihongyu.com/

你可能感兴趣的文章
【转】Android随笔之——PackageManager详解
查看>>
MyBatis框架——mybatis插入数据返回主键(mysql、oracle)
查看>>
HBase的单节点集群详细启动步骤(分为Zookeeper自带还是外装)
查看>>
Android学习探索之本地原生渲染 LaTeX数据公式
查看>>
MySQL缓存分类和配置
查看>>
COFF,amd64.vc90.mfc两个布署的问题
查看>>
谈谈MySQL死锁之二 死锁检测和处理源码分析
查看>>
全球最牛的100家AI创企:有多少独角兽?
查看>>
iOS8开发之iOS8的UIAlertController
查看>>
python自定义库文件路径
查看>>
sed命令
查看>>
Xcode6:解决_NSURLAuthenticationMethodServerTrust异常问题
查看>>
Vue 小项目的最佳实践
查看>>
web开发,让用户流水线进行操作,不可返回后退
查看>>
linux下javadoc生成文件出现中文乱码
查看>>
cocos2d-x项目101次相遇-安装和环境搭建 -xcode
查看>>
Android动态设置字体颜色
查看>>
引用类型与值类型
查看>>
hbase 0.98.1集群安装
查看>>
java调试打断点和不打断点执行结果不一致问题解决
查看>>