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:

        <ul>
<li (click)="person$.next(person)" *ngFor="#person of people | async">
{{person.name}} is in {{person.time | date : 'jms'}}
</li>
</ul> ... 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: })
}
} return person;
});
default:
return state;
}
};

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

[Angular 2] Using a Reducer to Change an Object's Property Inside an Array的更多相关文章

  1. NAMESPACE_ERR: An attempt is made to create or change an object in a way which is incorrect with regard to namespaces.

    解决办法: http://stackoverflow.com/questions/4037125/namespace-err-an-attempt-is-made-to-create-or-chang ...

  2. spring webservice 搭建出现的异常处理。异常: NAMESPACE_ERR: An attempt is made to create or change an object in a way whi

    异常:NAMESPACE_ERR: An attempt is made to create or change an object in a way whi---- 这是我自己写客户端调用webse ...

  3. Constants in C++

    The first motivation for const seems to have been to eliminate the use of preprocessor #define for v ...

  4. PHP 使用用户自定义的比较函数对数组中的值进行排序

    原文:PHP 使用用户自定义的比较函数对数组中的值进行排序 usort (PHP 4, PHP 5) usort —      使用用户自定义的比较函数对数组中的值进行排序 说明       bool ...

  5. angular源码分析:angular中脏活累活承担者之$parse

    我们在上一期中讲 $rootscope时,看到$rootscope是依赖$prase,其实不止是$rootscope,翻看angular的源码随便翻翻就可以发现很多地方是依赖于$parse的.而$pa ...

  6. [Angular 2] ngrx/store

    @ngrx/store builds on the concepts made popular by Redux and supercharges it with the backing of RxJ ...

  7. Angular源代码学习笔记-原创

    时间:2014年12月15日 14:15:10 /** * @license AngularJS v1.3.0-beta.15 * (c) 2010-2014 Google, Inc. http:// ...

  8. angular 2+ 变化检测系列二(检测策略)

    我们将创建一个简单的MovieApp来显示有关一部电影的信息.这个应用程序将只包含两个组件:显示有关电影的信息的MovieComponent和包含执行某些操作按钮的电影引用的AppComponent. ...

  9. angular组件之间的通讯

    组件通讯,意在不同的指令和组件之间共享信息.如何在两个多个组件之间共享信息呢. 最近在项目上,组件跟组件之间可能是父子关系,兄弟关系,爷孙关系都有.....我也找找了很多关于组件之间通讯的方法,不同的 ...

随机推荐

  1. Objective-C 笔记二 类、对象和方法

    对象就是一个物件.面向对象的程序设计可以看成一个物件和你想对它做的事情.这与C语言不同,C语言通常称为过程性语言.在C语言中,通常是先考虑要做什么,然后才关注对象,这几乎总是与面相对象的思考过程相反. ...

  2. ODAC的安装以及Entity Framework for Oracle 基本配置

    1.安装ODAC 根据自己操作系统x86,x64来判断下载的ODAC版本 http://www.oracle.com/technetwork/database/windows/downloads/ut ...

  3. gearmand的安装

    1.安装gperf libuuid-devel yum install -y gperf libuuid-devel 2.安装 libevent yum install libevent libeve ...

  4. 文件操作-php

    <?php /* 建立缓存 可以用文件长时间保存数据 文件是以liunux为模型的 在Windows下只能获取file ,dir unknow linux 下可以获取block char dir ...

  5. jquery元素查找方法

    $("#myELement") 选择id值等于myElement的元素,id值不能重复在文档中只能有一个id值是myElement所以得到的是唯一的元素 $("div&q ...

  6. Android 数据库读取数据显示 [5]

    2016-12-1 课程内容 昨天学了Android数据库升级.降级.创建 今天把数据库表里面的数据读取出来显示到手机屏幕上 下面代码是MainActivity.java 的代码 package co ...

  7. jQuery全选、反选、全不选

    原文链接:https://yq.aliyun.com/articles/33443 HTML内容部分: <ul id="items"> <li> <l ...

  8. iOS开发网络篇—JSON数据的解析

    iOS开发网络篇—JSON数据的解析 iOS开发网络篇—JSON介绍 一.什么是JSON JSON是一种轻量级的数据格式,一般用于数据交互 服务器返回给客户端的数据,一般都是JSON格式或者XML格式 ...

  9. SignTool.exe(签名工具)

    水漂收集 -- SignTool.exe(签名工具) =============C#.Net 篇目录============== 签名工具是一个命令行工具,用于用证书对文件进行数字签名,验证文件和时间 ...

  10. 【HDOJ】1276 士兵队列训练问题

    初看这道题目很像尤瑟夫问题, 区别是每次都是从1开始.解法也很类似.数学解递推公式.假定第K次报数后,余下人数不超过3个人.若第K次为1-3报数,那么由这三个数的当前索引n可推上一次报数之前的编号为n ...