Skip to content

Instantly share code, notes, and snippets.

@kosich
Last active February 22, 2019 16:58
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 kosich/d2bf182b21641d77720c514d68155b7b to your computer and use it in GitHub Desktop.
Save kosich/d2bf182b21641d77720c514d68155b7b to your computer and use it in GitHub Desktop.
const { rxObserver } = require('api/v0.3');
const { Observable } = require('rxjs/Rx');
const { timer } = require('rxjs');
const autoSave$ = Observable
.timer(0, 17)
.map(v => v%2 == 1)
.takeUntil(timer(100))
.share();
const changes$ =Observable
.timer(5, 10)
.takeUntil(timer(100))
.share();
const output$ =
autoSave$
.mergeMap(value =>
value
? changes$
.takeUntil(autoSave$)
: changes$
.bufferWhen(()=> autoSave$.filter(v=>v))
.take(1)
.flatMap(x=>x)
);
changes$.subscribe(rxObserver('Changes'));
autoSave$.subscribe(rxObserver('Auto save toggle'));
output$.subscribe(rxObserver('Output'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment