Skip to content

Instantly share code, notes, and snippets.

@Ibro
Created April 28, 2017 05:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ibro/11a797e96abe3d5be4c83301bd1a4aea to your computer and use it in GitHub Desktop.
Save Ibro/11a797e96abe3d5be4c83301bd1a4aea to your computer and use it in GitHub Desktop.
RxJS - Toggle the stream - Buffer - Coding Blast - www.codingblast.com
import {Observable} from 'rxjs';
let checkbox = document.getElementById('gates');
let checked = Observable
.fromEvent(checkbox, 'change')
.map((e: any) => e.target.checked);
let div = document.getElementById('output');
let source = Observable
.interval(100) // interval starts from 0
.scan((acc, val) => acc + val);
checked.filter(c => c === true)
.flatMap(() => source)
.subscribe(value => div.innerText += ` ${value}`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment