[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 ...
随机推荐
- ViewPager 嵌套Listview 让Listview响应 ViewPager 左右滑事件
一段拦截判断而已. 之前一直误解了一个拦截的描述.导致搞了半天. 结论: onInterceptTouchEvent 返回true,就由本身View的onTouchEvent进行事件消费. /** ...
- 二、T4模板
上文带大家见识了下T4,这里呢开始介绍T4模板有关的内容.关于T4模板介绍和使用网上一搜一箩筐,想深入研究的可以自行去找些资料,这里只介绍接下来我们需要使用的一些知识,不会面面俱到的讲T4模板所有的知 ...
- 99%Bug 修复方法
以下仅支持4.0.3或之后的设备 (写在前面,这个教程需要安装两个app,且卸载后无法达到效果,所以有app drawer洁癖者慎重(你可以把它们隐藏起来么). 当然等官方rom更新或者安装最新三方r ...
- iOS开发中的常用宏定义
在iOS开发的过程中合理的使用宏定义能够极大提高编码的速度,下面是一些常用的宏定义,部分内容来自互联网 Log // 调试状态, 打开LOG功能 #ifdef DEBUG #define GLLog( ...
- cas sso单点登录系列6_cas单点登录防止登出退出后刷新后退ticket失效报500错
转(http://blog.csdn.net/ae6623/article/details/9494601) 问题: 我登录了client2,又登录了client3,现在我把client2退出了,在c ...
- MFC框架类、文档类、视图类相互访问的方法
1.获取应用程序指针 CMyApp* pApp=(CMyApp*)AfxGetApp(); 2.获取主框架指针 CWinApp 中的公有成员变量 m_pMainWnd 就是主框架的指针 CMainFr ...
- 用BroadcastReceiver监听网络状态的变化
在用户浏览网络信息时,如果网络突然断开,可以及时的提醒用户网络已断开.要实现这个功能,我们可以实现一个广播接收者来接收网络状态改变的广播,当由连接状态变为断开状态时,系统会发送一条广播,广播接收者接收 ...
- Razor引擎的转换数据类型
AsInt() 把字符串转换为整数. if (myString.IsInt()) IsInt() {myInt=myString.AsInt();} AsFloat() 把字符串转换为浮点数. if ...
- @font-face扒站的步骤
今天模仿百度首页手机版的时候遇到的@font-face的问题,现在整理一下. 问题:图中红色区域,在拷贝F12样式的时候,并没有出现这些小图标. 图1:百度的效果 ...
- Thinkphp发布文章获取第一张图片为缩略图实现方法
正则匹配图片地址获取第一张图片地址 此为函数 在模块或是全局Common文件夹中的function.php中 /** * [getPic description] * 获取文本中首张图片地址 * @p ...