Last active
February 22, 2019 16:58
-
-
Save kosich/d2bf182b21641d77720c514d68155b7b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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