[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 ...
随机推荐
- sql - 面试
一,关于 group by 表内容: 2005-05-09 胜 2005-05-09 胜 2005-05-09 负 2005-05-09 负 2005-05-10 胜 2005-05-10 负 200 ...
- idea sass scss配置
1.安装Ruby win 直接http://rj.baidu.com/soft/detail/22711.html?ald mac linux https://ruby.taobao.org/ 可下 ...
- Java Calendar 计算时间差
public static void main(String[] args) { Calendar c=Calendar.getInstance(); int y=2016;//年 int M=1;/ ...
- Python文件之----XML
#coding=utf-8 from xml.dom import minidom from xml.dom.minidom import Document import xml def writeX ...
- jQuery firefox chrome IE 绑定mousewheel事件
$doc.on('mousewheel DOMMouseScroll',function(){ $htmlBody.stop(true); $goTop.stop(true); });
- TalkingData Cocos2dx集成指南【最新】
续:最近终于腾出时间把TalkingData的Cocos版本好好折腾一下了,总感觉之前的各个版本在集成上都很蹩脚.给广大开发者带了很多困扰...“游戏正着急上线呢,哪还有时间去仔细看TalkingDa ...
- 疯狂学习java web4(jsp)
JSP与PHP.ASP.ASP.NET等语言类似,运行在服务端的语言. JSP(全称Java Server Pages)是由Sun Microsystems公司倡导和许多公司参与共同创建的一种使软件开 ...
- Windows 7如何限制运行特定的应用程序(转载)
AppLocker即"应用程序控制策略",是Windows 7系统中新增加的一项安全功能. 步骤/方法 1 单击"开始"菜单,单击"控制面板" ...
- JS动态加载 js css
1.动态加载js function loadScript( url ){ var script = document.createElement( "script" ); scri ...
- Linux 搭建php扩展开发框架
1.安装phpize(如果是使用php源码编译就免了,本身就有) 2.打开php源码,ext中有ext_skel工具,使用它可以方便 ./ext_skel --extname = myext 生成扩展 ...