[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组件之间的通讯
组件通讯,意在不同的指令和组件之间共享信息.如何在两个多个组件之间共享信息呢. 最近在项目上,组件跟组件之间可能是父子关系,兄弟关系,爷孙关系都有.....我也找找了很多关于组件之间通讯的方法,不同的 ...
随机推荐
- 对DNSPOD添加域名解析的一些见解
1.主机记录这步比较简单,输入“www”表示比较常规的域名例如www.abc.com,“@”表示abc.com,“ * ”表示泛解析,匹配所有*.abc.com的域名. 2.记录类型这步,一般常用A记 ...
- iOS学习笔记(十四)——打电话、发短信
电话.短信是手机的基础功能,iOS中提供了接口,让我们调用.这篇文章简单的介绍一下iOS的打电话.发短信在程序中怎么调用. 1.打电话 [[UIApplication sharedApplicatio ...
- JavaScript_数组
/** * 数组本身也是对象 * js中数组类似于java里的map容器 长度可随意改变 ,元素类型任意 * */ // var arr = new Array(); // var arr = [1, ...
- IDEA中添加各种依赖pom.xml文件内容
刚实习的小白,今天准备进入项目,纳尼,前辈把框架什么的都搭建好了,默默的抹了一把辛酸泪,刚刚接触自学框架的时候,添加依赖的时候总是各种问题,让前辈发给我之后,才发现人家写的代码相当优美了.下面就是前辈 ...
- 【USACO 1.5.1】数字金字塔
[题目描述] 观察下面的数字金字塔. 写一个程序来查找从最高点到底部任意处结束的路径,使路径经过数字的和最大.每一步可以走到左下方的点也可以到达右下方的点. 7 3 8 8 1 0 2 7 4 4 4 ...
- PHP添加、更新solr索引
<?php $options = array ( 'hostname' => 'localhost', 'port' => '8080', 'path'=>'solr/help ...
- 富文本web编辑器(UEditor)
展示效果:
- jQuery键盘控制方法,以及键值(keycode)对照表
键盘控制应用范围非常广泛,比如快捷键控制页面的滚动:在填写表单时候,限制输入内容:或者是屏蔽复制.粘贴.退后等功能.这里说说用jQuery怎么来实现.个人觉得jQuery比原生态的JS好用,代码简单清 ...
- javascript 向上滚动
<html xmlns="http://www.w3.org/1999/xhtml"><head> <meta http-equiv="Co ...
- jquery easy ui 学习 (3) window 限制在父类窗体内
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...