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. Android之fragment点击切换和滑动切换结合

    学了一小段时间的Android,主要接触的是UI设计,打交道最多莫过于fragment了吧.在Android3.0引入了fragment的概念后,几乎在所以的Android的应用中都可以看见其身影,已 ...

  2. WPF命令

    WPF的命令是经常使用的,在MVVM中,RelayCommand更是用得非常多,但是命令的本质究竟是什么,有了事件为什么还要命令,命令与事件的区别是什么呢?MVVM里面是如何包装命令的呢?命令为什么能 ...

  3. 安卓之cannot convert from Fragment1 to Fragment

    在写一个音乐播放器的时候,用到了fragment,结果在需要返回Fragment的方法里面,无法将Fragment1(Fragment的子类)强制转换成Fragment, 很是纳闷,我是参照一个开源代 ...

  4. Unique Binary Search Tree

    Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For examp ...

  5. VBoxManage 命令行使用

    原文地址:http://cnjun939.blog.163.com/blog/static/78144538201251474311135/ 由于最近需研究virtualbox,看好看到上面的网址有, ...

  6. CentOS6.5安装LAMP环境的前期准备

    首先需要按照前一篇<CentOS 6.5下安装MySql 5.7>的安装步骤配置好防火墙.关闭 SELINUX 1.编译安装libxml2注:libxml2是一个xml的c语言版的解析器, ...

  7. eval函数:\的应用

    <?php $string = "beautiful"; $time = "winter"; $str = 'This is a $string $tim ...

  8. 【转】.NET开发者必备的11款免费工具

    摘要:本文介绍一些最适合.NET开发人员简化Web开发的最佳工具,这些工具都是开源的,有的开发工具你既可以从网上下载可执行文件,也可以下载源代码.一些工具拥有可扩展的框架,是一个持续集成工具. 原文链 ...

  9. mysql存储过程的权限 definer

    mysql中用户对存储过程的权限有: ALTER ROUTINE 编辑或删除存储过程 CREATE ROUTINE 创建存储过程 EXECUTE运行存储过程 存储过程的创建者拥有存储过程的ALTER. ...

  10. linux c数据库备份第二版

    #想知道更多请查看第一版"linux c数据库备份第一版" #include<sys/types.h> #include<sys/wait.h> #incl ...