[Angular 2] Using a Value from the Store in a Reducer
Angular in The from value Using Store reducer
2023-09-14 08:59:20 时间
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 项目 |Top 5 技巧
- The method setPositiveButton(int, DialogInterface.OnClickListener) in the type AlertDialog.
- 模块化开发 Angular 应用 [含懒加载]
- Angular HTTP 请求自定义 timeout 值的一种实现思路
- Angular面试题_session面试题
- 干货 | 一文搞懂在AlmaLinux上安装Angular JavaScript框架
- 关于在 Angular 应用里重复调用 RouterModule.forRoot(ROUTES) 的讨论
- Angular 模块封装概念常见的错误理解
- Angular Feature Modules
- Angular SSR 应用启动时的一些保护措施
- Angular 应用 tsconfig.json 文件里的 typeRoots 属性讲解
- ORA-48414: The string in the execution option exceeds maximum length [string] ORACLE 报错 故障修复 远程处理
- ORA-48444: The single “.” and “*” cannot appear in the middle of the path ORACLE 报错 故障修复 远程处理
- ORA-02324: more than one column in the SELECT list of THE subquery ORACLE 报错 故障修复 远程处理
- in Neo4j查询:使用Not In操作(neo4j查询not)
- 的区别MySQL中ON与IN的区别探讨(mysql中on与in)
- 和in的区别深入研究MySQL查询条件中的=与IN的区别(mysql查询条件中)
- Oracle游标IN模式使用指南(oracle游标in)
- Web 前端框架:Angular 4.0.0 正式版发布
- 查询优化Oracle中IN查询的技巧(oracle优化in)
- MySQL 中的 IN 语句分析(mysql语句in)
- 如何在MySQL中代替IN关键字(mysql中代替in)
- MySQL中使用IN类型参数(mysql中in类型参数)
- MySQL中如何使用IN操作符(mysql中in怎么写)
- MySQL IN函数的使用方法和注意事项(mysql 中in函数)
- MySQL中IN操作不去重,如何解决重复数据问题(mysql中in 不去重)
- 深究Oracle中的IN子查询(oracle中in子查询)
- 的影响Oracle中IN操作对索引效率的影响研究(oracle中in对索引)
- 查询Oracle中使用IN关键字查询多个值的方法(oracle中in多个值)
- 利用Oracle中的If In语句减少数据处理时间(oracle中if in)
- 提升Oracle IN操作中的性能改进(oracle in的性能)
- angular.element方法汇总