[RxJS] Creation operators: fromEventPattern, fromEvent
Besides converting arrays and promises to Observables, we can also convert other structures to Observables. This lesson teaches how we can convert any addEventHandler/removeEventHandler API to Observables.
var foo = Rx.Observable.fromEvent(document, 'click');
foo.subscribe(function (x) {
console.log('next ' + x);
}, function (err) {
console.log('error ' + err);
}, function () {
console.log('done');
});
fromEventPattern(addEventHandler, removeEventHandler): take two functions
function addEventHandler(handler){
document.addEventListener('click', handler)
}
function removeEventHandler(handler){
document.removeEventListener('click', handler)
}
var foo = Rx.Observable.fromEventPattern(addEventHandler, removeEventHandler);
foo.subscribe(function (x) {
console.log('next ' + x);
}, function (err) {
console.log('error ' + err);
}, function () {
console.log('done');
});
[RxJS] Creation operators: fromEventPattern, fromEvent的更多相关文章
- [RxJS] Creation operators: interval and timer
It is quite common to need an Observable that ticks periodically, for instance every second or every ...
- [RxJS] Creation operators: empty, never, throw
This lesson introduces operators empty(), never(), and throw(), which despite being plain and void o ...
- [RxJS] Creation operators: from, fromArray, fromPromise
The of() operator essentially converted a list of arguments to an Observable. Since arrays are often ...
- [RxJS] Creation operator: of()
RxJS is a lot about the so-called "operators". We will learn most of the important operato ...
- [RxJS] Creation operator: create()
We have been using Observable.create() a lot in previous lessons, so let's take a closer look how do ...
- Rxjs常用operators
本文使用的是angular6内置的rxjs,版本号为6.3.3 concat 通过顺序地发出多个 Observables 的值将它们连接起来,一个接一个的. 参数: 名称 类型 属性 描述 other ...
- [RxJS] Transformation operators: debounce and debounceTime
Debounce and debounceTime operators are similar to delayWhen and delay, with the difference that the ...
- [RxJS] Transformation operators: delay and delayWhen
This lessons teaches about delay and delayWhen: simple operators that time shift. delay(number | dat ...
- [RxJS] Filtering operators: skipWhile and skipUntil
After takeUntil() and takeWhile() function, let's have a look on skipWhile() and skilUntil() functio ...
随机推荐
- Android中使用PullToRefreshListView遇到的问题
1.布局文件中要是设置visible属性为Gone的时候,注意了,这样会有一个bug,在代码中setVisible的时候设置为VISIBLE是不起作用的..这个应该是自身的一个小bug(本人目前没有找 ...
- SQL Server主键自动生成_表and存储过程
主键表: CREATE TABLE [dbo].[KEYCODE]( [KeyName] [varchar](12) NOT NULL, [KeyTableName] [varchar](40) NU ...
- 重新开始学习javase_集合_List
一,List之ArrayList(转:http://blog.csdn.net/zheng0518/article/details/42198205) 1. ArrayList概述: ArrayLis ...
- jQuery banner 滑动
jQuery(document).ready(function() { var abovePos = 50; var customMax = 1600; var zIdx = 100; var $bn ...
- protobuf的反射机制
反射机制 java在运行状态时,能够知道任意类的所有属性和方法,都能够调用任意对象的任意方法和属性.这种动态获取的信息以及动态调用对象的方法的功能称为java语言的反射机制. C++本身没有反射机制. ...
- canvas 渐变
那么第一种渐变方式就是LinearGradient,具体实施就是以下代码: var colorStyle=context.createLinearGradient(0,0,0,HEIGHT); col ...
- python使用platform模块获取系统环境并去除换行符
近来在porting一个网站,企图拿到这个网站的数据来做分析.为了支持多系统环境的正常运行.需要知道当前系统环境的是什么OS? 1.python内置platform库.可以很方便得到当前系统环境时什么 ...
- 大脑皮层是如何工作的 《人工智能的未来》(<On intelligence>)读书笔记
PS:今年寒假的读书笔记,挖下的坑已无力再填...不过有关智能和人工智能的书还是要继续读的~ 正文: 我觉得书名翻译不是很确切,全书讨论的核心应该更是在“真”智能:讨论对人脑智能的理解,可以怎样帮助我 ...
- UVA1152 4Values whose Sum is 0
Description The SUM problem can be formulated as follows: given four lists A, B, C, D of integer val ...
- mongod的主要参数有
------------------------------------基本配置---------------------- --quiet # 安静输出 --port arg # 指定服务端口号 ...