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. type和create type

    type和create type 异同点:      create type 可在库中生成一个长期有效的自定义类型对象,而type作用域仅限于语句块中:      两者都可以自定义数据类型: 各种ty ...

  2. WARN TaskSetManager: Lost task 0.0 in stage 0.0 (TID 0, worker1): java.lang.ClassNotFoundException: com.spark.firstApp.HelloSpark$$anonfun$2

    进行如下设置,解决报错信息. val conf = new SparkConf().setAppName("helloSpark").setMaster("spark:/ ...

  3. 跟我学android-Android应用结构分析(四)

    自动生成的R.java文件说明 public final class R { public static final class attr { } public static final class ...

  4. Ajax的原理和运行机制

    关于ajax,是最近炒得非常火的一种技术,并且时下它也是非常流行.当然,它并不是什么新技术,而是在各种已有的技术和支持机制下的一个统一.在我的项目中,偶尔也会用到ajax,用来给用户一些无刷新的体验. ...

  5. 我的github代码添加

    1.创建一个新的repository: echo "# backupVim" >> README.md git init git add README.md git c ...

  6. HTML语义化标签(二)

    为了保证网页去样式后的可读性,并且又符合web标准,应该注意一下几点: 1  尽可能少的使用无语义的标签div和span: 2  在语义不明显时,既可以使用div或者p时,尽量用p, 因为p在默认情况 ...

  7. javascript禁止输入数字

    function onkeypressIsNumber(){ var mainForm = document.mainForm;//mainForm是form表单的ID for(var i=0; i& ...

  8. 我牵头,你做事——C#委托实践

     我牵头,你做事——C#委托实践一 2007-09-05 23:54:54 标签:委托 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http ...

  9. Jssdk微信分享

    <?php require_once "jssdk.php"; $jssdk = new JSSDK("yourAppID", "yourApp ...

  10. PHP获取当前文件路径信息的方法

    文件名  test.php 1.__FILE__ 获取 “路径 + 文件名” : /var/www/test/test.php  echo __FILE__; //取得当前文件的路径:用魔术常量 __ ...