[Angular 2] Mapping Streams to Values to Affect State
While you have multiple streams flowing into your scan operator, you'll need to map each stream to the specific values you need to update your state the way that you want. This lesson covers using the map operator to determine what the click and interval should do when the state is updated.
import {Component} from 'angular2/core';
import {bootstrap} from 'angular2/platform/browser';
import {Observable} from 'rxjs/Observable';
import 'rxjs/add/observable/interval';
import 'rxjs/add/observable/merge';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/scan';
import 'rxjs/add/operator/startWith';
import {Subject} from 'rxjs/Subject';
@Component({
selector: 'app',
template: `
<button (click)="click$.next()">Add one second</button>
<h1>{{clock | async | date: 'yMMMMEEEEdjms'}}</h1>
`
})
class App {
click$ = new Subject();
clock;
constructor(){
this.clock = Observable.merge(
Observable.interval().mapTo('second'),
this.click$.mapTo('hour')
)
.startWith(new Date())
.scan( (acc: Date, curr: string) => {
// acc: new Date() passed from startWIth
// curr: string, passed from mapTo
console.log(acc, curr);
const date: Date = new Date(acc.getTime());
if(curr === "second"){
date.setSeconds(date.getSeconds() + );
}
if(curr === "hour"){
date.setHours(date.getHours() + );
}
return date;
});
}
}
bootstrap(App);
[Angular 2] Mapping Streams to Values to Affect State的更多相关文章
- Know How To Use Check Box Mapping Of Other Values Property In Oracle Forms
Check Box Mapping of Other Values specifies how any fetched or assigned value that is not one of the ...
- [Angular 2] Passing Template Input Values to Reducers
Angular 2 allows you to pass values from inputs simply by referencing them in the template and passi ...
- [Functional Programming] Read and Transform Values from a State ADT’s State (get)
Many times we need to access and transform state, either in part or in full, to be used when calcula ...
- BETTER SUPPORT FOR FUNCTIONAL PROGRAMMING IN ANGULAR 2
In this blog post I will talk about the changes coming in Angular 2 that will improve its support fo ...
- Angular之 Scope和 Directive
---------------------------Scope-------------------------------- https://docs.angularjs.org/guide/sc ...
- Angular (SPA) WebPack模块化打包、按需加载解决方案完整实现
文艺小说-?2F,言情小说-?3F,武侠小说-?9F long long ago time-1-1:A 使用工具,long long A ago time-1-2:A 使用分类工具,long long ...
- ocLazyLoad angular 按需加载
ionic 框架 1.引用 index.html 加载 <script type="text/javascript" src="lib/oclazyload/ocL ...
- angular --- s3core移动端项目(二)
product-ctrl.js angular.modules('myApp').controller('ProductCtrl',['$scope','$rootScope','$timeout', ...
- CHANGE DETECTION IN ANGULAR 2
In this article I will talk in depth about the Angular 2 change detection system. HIGH-LEVEL OVERVIE ...
随机推荐
- 抓取锁的sql语句-第三次修改
CREATE OR REPLACE PROCEDURE SOLVE_LOCK AS V_SQL VARCHAR2(3000); --定义 v_sql 接受抓取锁的sql语句CUR_LOCK SYS_R ...
- IOS中截屏的实现,很简易的方法
// 添加QuartzCore.framework库 #import <QuartzCore/QuartzCore.h> -(void) screenShot { // 截屏 UIGrap ...
- Cisco CatOS系统交换机的SPAN配置
以下内容摘自最新上市的“四大金刚”图书之一<Cisco交换机配置与管理完全手册>(第二版)(其它三本分别为<Cisco路由器配置与管理完全手册>(第二版).<H3C交换机 ...
- php 文件操作之抓取网站图片
$str= file_get_contents("http://v.qq.com/");preg_match_all("/\<img\s+src=.*\s*\> ...
- SCJP_104——题目分析(3)
11. what is reserved words in java?A. run B. default C. implement D. import Java 中,给标识符取名的时候,不能使用关键字 ...
- CodeKata
http://codekata.pragprog.com/2007/01/code_kata_backg.html#more 背景 你如何成为一个伟大的音乐家?它有助于知道理论,了解仪器的机制.它有助 ...
- PHP 5.6正式发布:新特性、及功能改进介绍
经过了长时间的开发测试,新版本PHP程序(PHP5.6正式版)终于发布了.新版本中加入了一些实用的新特性,也摒弃了一些冗余的功能.同时,也对部分原有功能进行了改进.下面就一起看看PHP 5.6正式版到 ...
- Solr4.8.0源码分析(1)之Solr的Servlet
Solr是作为一个Servlet运行在Tomcat里面的,可以查看Solr的web.xml. 1.web.xml配置 由web.xml可以看出,基本上所有Solr的操作都是在SolrDispatchF ...
- LeetCode_ 4 sum
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = tar ...
- Understanding GC pauses in JVM, HotSpot's minor GC.
原文地址:http://blog.griddynamics.com/2011/06/understanding-gc-pauses-in-jvm-hotspots.html Stop-the-worl ...