RxJS allows you to combine streams in various ways. This lesson shows you how to take a click stream and combine it with a store stream to use a value from the store inside a reducer.

The logic is when we click the recall button, it will reset all the people's time to the current time.

First, bind the click event to recall$:

<button (click)="recall$.next()">Recall</button>

...

recall$ = new Subject();

We get the latest time from the time stroe:

    constructor(store:Store) {
this.time = store.select('clock');
this.people = store.select('people'); Observable.merge(
this.click$,
this.seconds$,
this.person$,
this.recall$
.withLatestFrom(this.time, (_, y) => y) // _: means don't need to care about the first param which is this.recall$
.map( (time) => ({type: RECALL, payload: time}))
)
.subscribe(store.dispatch.bind(store))
}

_: is naming convention, it means, don't care about the first value.

Last, we handle the action in reducer:

        case RECALL:
return state.map( (person) => {
return {
name: person.name,
time: payload
};
})

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

[Angular 2] Using a Value from the Store in a Reducer的更多相关文章

  1. [Angular 2] Using ngrx/store and Reducers for Angular 2 Application State

    ngrx/store is a library that simplifies common RxJS patterns for managing state and gives you an eas ...

  2. 手把手教你用ngrx管理Angular状态

    本文将与你一起探讨如何用不可变数据储存的方式进行Angular应用的状态管理 :ngrx/store——Angular的响应式Redux.本文将会完成一个小型简单的Angular应用,最终代码可以在这 ...

  3. [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 sh ...

  4. [Angular 2] Passing Observables into Components with Async Pipe

    The components inside of your container components can easily accept Observables. You simply define ...

  5. Redux系列01:从一个简单例子了解action、store、reducer

    其实,redux的核心概念就是store.action.reducer,从调用关系来看如下所示 store.dispatch(action) --> reducer(state, action) ...

  6. 【React】Redux入门 & store体验

    组件间传值联动是令人头疼的问题,尤其是一个组件影响多个其他组件状态变化的时候,常常需要一级一级与父组件传值,与父组件的兄弟组件传值等等, 如何化繁为简地处理‘牵一发动全身’的清理就是将所有组件的sta ...

  7. Redux教程3:添加倒计时

    前面的教程里面,我们搭建了一个简单红绿灯示例,通过在console输出当面的倒计时时间:由于界面上不能显示倒计时,用户体验并不良好,本节我们就添加一个简单的倒计时改善一下. 作为本系列的最后一篇文章, ...

  8. 如何在AngularX 中 使用ngrx

    ngrx 是 Angular框架的状态容器,提供可预测化的状态管理. 1.首先创建一个可路由访问的模块 这里命名为:DemopetModule. 包括文件:demopet.html.demopet.s ...

  9. angular2 学习笔记 ( 状态管理 state management )

    更新 : 2017-12-29  ng5 移除 zone.js https://zhuanlan.zhihu.com/p/29577461 zone 的用途就是拦截游览器事件, 比如 click, a ...

随机推荐

  1. Oracle增加自增长列

    -- 移除索引drop index TB_1;drop index TB_2 ;alter table TB drop constraint PK_TB; --允许列为空 alter table TB ...

  2. mac在 aliyun linux ecs实例上安装 jdk tomcat mysql

    用了一个ftp 工具 把 gz rpm 等 传递到ecs 上 -- 用这个Transmit 用ssh远程登录,然后依次安装 jdk tomcat  mysql 到 /usr/local/... 设置环 ...

  3. Linux命令--用户用户组管理

    新增用户组 : groupadd groupadd [-g GID] 组名 不加-g 则按照系统默认的gid创建组,跟用户一样,gid也是从500开始的 修改用户组信息 : groupmod grou ...

  4. 用Hopper搞定Mac迅雷的会员以及离线下载功能

    转自 用Hopper搞定Mac迅雷的会员以及离线下载功能 先定位Mac迅雷的可执行文件 snakeninnys-iMac:~ snakeninny$ ls /Applications/Thunder. ...

  5. [转]Delphi 关键字详解

    全文链接地址:http://www.cnblogs.com/del/archive/2008/06/23/1228562.html

  6. window连接linux nfs服务器 —— 网络错误 53

    在度娘以"win7 nfs mount 网络错误 - 53"为关键字,翻了第一页,GG... 于是去找谷哥,第一页 [all variants] Get NFS working w ...

  7. C++变量的“总分性”(Mereology)

    Stroustrup 在自传中说自己在哲学上深受 Kierkegaard (吉爾凱高爾)的影响,而讨厌黑格尔.所以看 Stroustrup 的书,很少感受到抽象理论的重要性.这也影响了C++的文化:许 ...

  8. JavaScript设计模式之建造者模式

    一.建造者模式模式概念 建造者模式可以将一个复杂的对象的构建与其表示相分离,使得同样的构建过程可以创建不同的表示.也就是说如果我们用了建造者模式,那么用户就需要指定需要建造的类型就可以得到它们,而具体 ...

  9. Spring4.0学习笔记(7) —— 通过FactoryBean配置Bean

    1.实现Spring 提供的FactoryBean接口 package com.spring.facoryBean; import org.springframework.beans.factory. ...

  10. 无法解析属性“mode”的值。错误为: 枚举值必须是以下各值中的一个: RemoteOnly, On, Off。

    Off首字母要大写,注意大小写 <customErrors mode="Off">      <error statusCode="404" ...