[RxJS] Returning subscriptions from the subscribe function
So far, when writing these subscribe functions, we haven't returned anything. It is possible return an unsubscribe function from a subscribe function. In this lesson we will see how to allow observers to subscribe and unsubscribe from an Observable.
var foo = new Rx.Observable(function subscribe(observer) {
var id = setInterval(function () {
observer.next('hi');
}, );
return function unsubscribe() {
clearInterval(id);
};
});
var subscription = foo.subscribe({
next: function (x) { console.log('next ' + x); },
error: function (err) { console.log('error ' + err); },
complete: function () { console.log('done'); },
});
setTimeout(function () {
subscription.unsubscribe();
}, );
[RxJS] Returning subscriptions from the subscribe function的更多相关文章
- [Go] Returning Multiple Values from a Function in Go
Returning multiple values from a function is a common idiom in Go, most often used for returning val ...
- [RxJS] Basic DOM Rendering with Subscribe
While frameworks like Angular 2 and CycleJS provides great ways to update the DOM and handle subscri ...
- MVVM架构~knockoutjs系列之从Knockout.Validation.js源码中学习它的用法
返回目录 说在前 有时,我们在使用一个插件时,在网上即找不到它的相关API,这时,我们会很抓狂的,与其抓狂,还不如踏下心来,分析一下它的源码,事实上,对于JS这种开发语言来说,它开发的插件的使用方法都 ...
- [TypeScript] Understanding Generics with RxJS
Libraries such as RxJS use generics heavily in their definition files to describe how types flow thr ...
- Angular快速学习笔记(4) -- Observable与RxJS
介绍RxJS前,先介绍Observable 可观察对象(Observable) 可观察对象支持在应用中的发布者和订阅者之间传递消息. 可观察对象可以发送多个任意类型的值 -- 字面量.消息.事件. 基 ...
- RxJS库
介绍 RxJS是一个异步编程的库,同时它通过observable序列来实现基于事件的编程.它提供了一个核心的类型:Observable,几个辅助类型(Observer,Schedulers,Subje ...
- rxjs的世界
rxjs学习了几个月了,看了大量的东西,在理解Observable的本文借鉴的是渔夫的故事,原文,知识的主线以<深入浅出rxjs>为主,动图借鉴了rxjs中文社区翻译的文章和国外的一个动图 ...
- [RxJS] Error handling operator: catch
Most of the common RxJS operators are about transformation, combination or filtering, but this lesso ...
- [RxJS + AngularJS] Sync Requests with RxJS and Angular
When you implement a search bar, the user can make several different queries in a row. With a Promis ...
随机推荐
- Binary XML file : Error inflating class com.esri.android.map.MapView
在测试esri arcgis for android的第一个程序Helloworld的时候,报这样的错: Binary XML file : Error inflating class com.esr ...
- get the text value of a selected option.
<select id="myselect"> <option value="1">Mr</option> <optio ...
- drop table xx purge
drop table xx purge; 说明: 所有删除的表都会在回收站里面,只有后面加上purge才是彻底的清空表. (一般用于测试.练习数据表,所以最好不要带purge,要不误删就找不到了.)
- 设置windows窗口ICON 【windows 编程】【API】【原创】
1. ICON介绍 最近开始接触windows 编程,因此将自己所接触的一些零散的知识进行整理并记录.本文主要介绍了如何更改windows对话框窗口的ICON图标.这里首先介绍一下windows IC ...
- 【USACO 1.3.4】牛式
[題目描述 ] 下面是一个乘法竖式,如果用我们给定的那n个数字来取代*,可以使式子成立的话,我们就叫这个式子牛式. * * * x * * ---------- * * * * * * ------- ...
- 临时设置 selinux
setenforce 0 ##设置SELinux 成为permissive模式 ##setenforce 1 设置SELinux 成为enforcing模式
- angularJS学习笔记一
AngularJS是为了克服HTML在构建应用上的不足而设计的.HTML是一门很好的为静态文本展示设计的声明式语言,但要构建WEB应用的话它就显得乏力了.所以我做了一些工作(你也可以觉得是小花招)来让 ...
- Linux下Openfire相关安装和配置
记录下来,方便下次再用时从头查找资料 小京东ecshop中的通讯有用到openfire,Window下配置安装很简单,直接下载exe文件安装就行,而linux下要麻烦一点.安装后的配置下面会细说: 一 ...
- Linux 下安装Python框架django建立与mysql的连接
0.基本环境说明: a. Ubuntu 14.04 64bit b. python 2.7.6 c. django 1.8 d. django-registration e. django-widge ...
- phpinfo.php
---恢复内容开始--- apache中的配置不对 查看httpd.conf文件中是否有: AddType ...... AddType application/x-httpd-php .php -- ...