[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 ...
随机推荐
- jAVA EE里什么是链式调用
链式调用就是每次调用完了过后返回的是自己,比如Hibernate里面执行hql需要设置参数时,每次设置完参数可以继续使用点设置下一个参数http://blog.sina.com.cn/s/blog_4 ...
- POJ3126 Prime Path (bfs+素数判断)
POJ3126 Prime Path 一开始想通过终点值双向查找,从最高位开始依次递减或递增,每次找到最接近终点值的素数,后来发现这样找,即使找到,也可能不是最短路径, 而且代码实现起来特别麻烦,后来 ...
- javascript学习(知识点整理)
有了这个代码,就可以在定义 中增加更多的控制了 后面会举例关于extjs定义的更多控制 此种方案可以解决定义时需要一些函数调用的情况 函数作用域和声明提前: 即由于js是解释性语言,在执行前会 ...
- Qt中widget重新setParent需要注意的问题
有时候需要在widget中重新setParent,但会发现setParent有时候会出现问题,比如子窗口不在刷出来等等. 其实,有一点是需要注意的,就是Qt文档里说的,如果你当前widget重新设置了 ...
- Java学习----main详解
public class Test1 { public static void main(String[] args) { System.out.println("Hello"); ...
- 【转载】如何学习javascript
如何学习Javascript 作者: chaomao 首先要说明的是,咱现在不是高手,最多还是一个半桶水,算是入了JS的门. 谈不上经验,都是一些教训. 这个时候有人要说,“靠,你丫半桶水,凭啥教我 ...
- IE6的bug
借鉴http://css.doyoe.com/ 问题和经验列表,里面应有尽有.写几个常见的: 1.解决IE6及更早浏览器浮动时产生双倍边距的BUG display:inline 2.如何解决IE6下的 ...
- jquery 事件绑定(1)
$(function(){ $("#panel h5.head").bind("click",function(){ $(this).next().show() ...
- POJ - 3903 Stock Exchange(LIS最长上升子序列问题)
E - LIS Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Descripti ...
- Python二分查找
代码: 时间复杂度:O(log2n) #!/usr/bin/env python #coding:utf-8 import copy from copy import deepcopy ''' def ...