[Angular 2] Using a Reducer to Change an Object's Property Inside an Array
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的更多相关文章
- 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 ...
- 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 ...
- Constants in C++
The first motivation for const seems to have been to eliminate the use of preprocessor #define for v ...
- PHP 使用用户自定义的比较函数对数组中的值进行排序
原文:PHP 使用用户自定义的比较函数对数组中的值进行排序 usort (PHP 4, PHP 5) usort — 使用用户自定义的比较函数对数组中的值进行排序 说明 bool ...
- angular源码分析:angular中脏活累活承担者之$parse
我们在上一期中讲 $rootscope时,看到$rootscope是依赖$prase,其实不止是$rootscope,翻看angular的源码随便翻翻就可以发现很多地方是依赖于$parse的.而$pa ...
- [Angular 2] ngrx/store
@ngrx/store builds on the concepts made popular by Redux and supercharges it with the backing of RxJ ...
- Angular源代码学习笔记-原创
时间:2014年12月15日 14:15:10 /** * @license AngularJS v1.3.0-beta.15 * (c) 2010-2014 Google, Inc. http:// ...
- angular 2+ 变化检测系列二(检测策略)
我们将创建一个简单的MovieApp来显示有关一部电影的信息.这个应用程序将只包含两个组件:显示有关电影的信息的MovieComponent和包含执行某些操作按钮的电影引用的AppComponent. ...
- angular组件之间的通讯
组件通讯,意在不同的指令和组件之间共享信息.如何在两个多个组件之间共享信息呢. 最近在项目上,组件跟组件之间可能是父子关系,兄弟关系,爷孙关系都有.....我也找找了很多关于组件之间通讯的方法,不同的 ...
随机推荐
- [转] 详细整理:UITableView优化技巧
原文:http://www.cocoachina.com/ios/20150602/11968.html 最近在微博上看到一个很好的开源项目VVeboTableViewDemo,是关于如何优化 ...
- Swift - 10 - assert(断言)
//: Playground - noun: a place where people can play import UIKit var str = "Hello, playground& ...
- ubuntu下apache与php配置
实验环境 uname -a Linux tomato 4.4.0-34-generic #53-Ubuntu SMP Wed Jul 27 16:06:39 UTC 2016 x86_64 x86_6 ...
- java学习——集合框架(泛型,Map)
泛型: ... Map:一次添加一对元素.Collection 一次添加一个元素. Map也称为双列集合,Collection集合称为单列集合. 其实map集合中存储的就是键值对. map集合中必须保 ...
- 比较两个字符,相等输出yes,不相等输出no
DATA SEGMENTSHOW1 DB 'YES$'SHOW2 DB 'NO$'DATA ENDSCODE SEGMENTASSUME CS:CODE,DS:DATABEGIN: MOV AX,DA ...
- 《asp.net mvc3 高级编程》第三章 视图
一.视图的作用 视图的职责是向用户提供界面.从ASP.NET MVC3开始,视图数据也可以通过ViewBag属性访问.例如:ViewBag.Message 就等于ViewData["Mess ...
- 请给出异步加载js方案
请给出异步加载js方案,不少于两种 默认情况javascript是同步加载的,也就是javascript的加载时阻塞的,后面的元素要等待javascript加载完毕后才能进行再加载,对于一些意义不是很 ...
- Nginx源码研究五:NGINX的配置信息管理
配置信息是nginx系统重要的组成部分,配置信息的使用,实际上包含两层,一层是用户针对参数定义了值,例如下面nginx参数文件中的 keepalive_timeout 65,还有一部分是用户没有定义值 ...
- Bug: freetype/fterrors.h: No such file or directory
Bug描述: 安装PIL过程中出现题目中的错误信息,具体如下:
- Spark笔记-treeReduce、reduce、reduceByKey
参考资料: http://stackoverflow.com/questions/32281417/understadning-treereduce-in-spark http://stackover ...