[RxJS] Stopping a Stream with TakeUntil
2016-03-09 16:32
615 查看
Observables often need to be stopped before they are completed. This lesson shows how to use
takeUntilto stop a running timer. Then we use the starting stream and the stopping stream together to create a simple stopwatch.
const Observable = Rx.Observable; const startButton = document.querySelector('#start'); const stopButton = document.querySelector('#stop'); const start$ = Observable.fromEvent(startButton, 'click'); const interval$ = Observable.interval(1000); const stop$ = Observable.fromEvent(stopButton, 'click'); const intervalThatStops$ = interval$ .takeUntil(stop$); start$ .switchMapTo(intervalThatStops$) .subscribe((x)=> console.log(x));
相关文章推荐
- js exploit
- maven 构建web项目index.jsp报错
- json常用jar包
- JS获取回车事件和文本焦点处理不同按钮提交信息
- JavaScript学习笔记
- 总结的JS数据类型判定(非常全面)
- javascript中callee与caller的用法和应用场景
- JS第11天
- JS中关于 一个关于计时器功能效果的实现
- js的二级联动
- net.sf.json.JSONException: There is a cycle in the hierarchy!
- 如何通过js获得overflow属性为auto的元素的实际宽度
- ArcGIS API for JavaScript 地图加载空白现象-ArcGIS Web 开发学习(三)
- js 中 setInterval 的返回值问题
- JSONArray的应用
- 几则js表达式
- 打印较长的json数据Log
- 使用Gson解析复杂的json数据
- js 正则表达式2
- js 正则表达式2