This lesson covers how to toggle an observable on and off from another observable by showing how to use a checkbox as a toggle for a stream of data.

<!DOCTYPE html>
<html>
<head>
<script src="https://npmcdn.com/@reactivex/rxjs@5.0.0-alpha.8/dist/global/Rx.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<input type="checkbox" id="toggle">
<div id="display"></div>
</body>
</html>
const display = document.querySelector('#display');
const toggle = document.querySelector('#toggle'); const source$ = Rx.Observable.interval(100)
.map(() => '.');
const checked$ = Rx.Observable.fromEvent(toggle, 'change')
.map(e => e.target.checked);
const sourceThatStop$ = source$.takeUntil(checked$); checked$
.filter( flag => flag === true)
.switchMapTo( sourceThatStop$ )
.subscribe( (x) => {
display.innerHTML += x;
});

[RxJS] Toggle A Stream On And Off With RxJS的更多相关文章

  1. [RxJS] Logging a Stream with do()

    To help understand your stream, you’ll almost always want to log out some the intermediate values to ...

  2. [RxJS] Stopping a Stream with TakeUntil

    Observables often need to be stopped before they are completed. This lesson shows how to use takeUnt ...

  3. [RxJS] Starting a Stream with SwitchMap & switchMapTo

    From an event map to another event we can use switchMap(), switchMap() accept an function which retu ...

  4. [RxJS] Completing a Stream with TakeWhile

    Subscribe can take three params: subscribe( (x)=> console.log(x), err=> console.log(err), ()=& ...

  5. [RxJS] Aggregating Streams With Reduce And Scan using RxJS

    What is the RxJS equivalent of Array reduce? What if I want to emit my reduced or aggregated value a ...

  6. [RxJS] Reactive Programming - Using cached network data with RxJS -- withLatestFrom()

    So now we want to replace one user when we click the 'x' button. To do that, we want: 1. Get the cac ...

  7. [RxJS] Reactive Programming - Clear data while loading with RxJS startWith()

    In currently implemention, there is one problem, when the page load and click refresh button, the us ...

  8. [RxJS] Reactive Programming - Rendering on the DOM with RxJS

    <!DOCTYPE html> <html> <head> <script src="https://code.jquery.com/jquery- ...

  9. [RxJS] Implement the `map` Operator from Scratch in RxJS

    While it's great to use the RxJS built-in operators, it's also important to realize you now have the ...

随机推荐

  1. 模块计算机类型“X64”与目标计算机类型“x86”冲突

    问题描述:在X64 平台上开发dll 文件,在生成dll时Vs 2010 出现如下错误 :"fatal error LNK1112: 模块计算机类型"X64"与目标计算机 ...

  2. iscc2016 mobile1-TurtleShell.apk解题过程

    拿到程序先运行,简单的验证输入的flag正确与否.jeb加载apk文件 实在库文件里面验证,所以ida加载之,so文件是加密的,所以看不到关键验证函数,百度搜了下libhackme.so,出来这篇文章 ...

  3. 编译lua5.3.2报错提示libreadline.so存在未定义的引用解决方法

    从官网上下载5.3.2的源码后,make linux进行编译,提示报错: gcc -std=gnu99 -o lua lua.o liblua.a -lm -Wl,-E -ldl -lreadline ...

  4. web_api vs2015 新加标题无法打开

    HomeController 去掉特性[Authorize]

  5. Spinner( 微调) 组件

    本节课重点了解 EasyUI 中 Spinner(微调)组件的使用方法,这个组件依赖于ValidateBox(验证框)组件. 一. 加载方式Spinner(微调)组件是其他两款高级微调组件的基础组件, ...

  6. C#,.net获取字符串中指定字符串的个数、所在位置与替换字符串

    方法一: public static int indexOf (字符串/字符,int从第几位开始,int共查几位) string tests = "1absjjkcbfka2rsbcfak2 ...

  7. 3:url无规律的多页面爬取

    试例网站:豆瓣电影TOP250:http://movie.douban.com/top250 关键点:在审查元素下查看后页即可以看到跳转的url.而且最后一页就此属性就没有了. 由于关键是实现分页,所 ...

  8. mysql 分区表详解

    项目中要一张库表实现 list分区.并且支持多种数据库. oracle 很顺利,只是mysql 听说5.1版本就已经支持了, 可是试了很多个版本,都不行,后来查到原因是要5.5 以上版本 分区才支持 ...

  9. js动态加载html,加载后的页面元素某些事件失效的解决方案

    用 live 来绑定 例如: $("#items li .addToCartimg").live("click",function(){ $('.popDeta ...

  10. JSP中页面定时刷新

    1.JSP中页面定时刷新 <% //页面每隔30秒自动刷新一遍 response.setHeader("refresh" , "30" ); %> ...