Skip to content

Instantly share code, notes, and snippets.

@Dorus
Created May 4, 2016 22:52
Show Gist options
  • Save Dorus/c78b4e9c43eb4f3d10eb1bb47bed8a55 to your computer and use it in GitHub Desktop.
Save Dorus/c78b4e9c43eb4f3d10eb1bb47bed8a55 to your computer and use it in GitHub Desktop.
Marble samples
var source$ = Rx.Observable.marble("1--23--456--7890--");
var enter$ = Rx.Observable.marble("-e-----e----------");
var exit$ = Rx.Observable.marble("---x-------x------");
var sampler$ = Rx.Observable.marble("a--b--c--d--e--f--");
var full$ = Rx.Observable.marble("01234567890abcdefg");
source$.draw('source', '#container')
.debounceTime(1050).draw('debounceTime(1)', '#container');
source$.auditTime(1050).draw('auditTime(1)', '#container');
source$.throttleTime(1050).draw('throttleTime(1)', '#container');
source$.delay(1000).draw('source.delay(1)', '#container');
source$.draw('source', '#container')
.map(i => i * 10).draw('source.map(i => i * 10)', '#container');
source$.scan((acc, cur) => acc + parseInt(cur), 0).draw('source.scan((acc, cur) => acc + cur)', '#container');
source$.filter(e => e % 2 === 0).draw('source.filter(e => e % 2 == 0)', '#container');
enter$.draw('enter', '#container')
.merge(exit$.draw('exit', '#container')).draw('merge(enter, exit)', '#container');
enter$.zip(exit$).draw('zip(enter, exit)', '#container');
full$.draw('full', '#container')
.sample(sampler$.draw('sampler', '#container')).draw('full.sample(sampler)', '#container');
sampler$.withLatestFrom(full$).draw('sampler.withLatestFrom(full)', '#container');
sampler$.combineLatest(full$).draw('sampler.combineLatest(full)', '#container');
full$.buffer(sampler$).draw('full.buffer(sampler)', '#container');
full$
.window(sampler$)
.flatMap(window =>
window
.reduce((acc, cur) => acc + parseInt(cur), 0)
).draw('full.window(sampler).flatMap(window => window.reduce(0, (acc, cur) => acc + cur))', '#container');
full$.bufferCount(3, 2).draw('full.bufferCount(3, 2)', '#container');
full$.bufferTime(2000).draw('full.bufferTime(2)', '#container');
full$.draw('full', '#container');
enter$.draw('enter', '#container');
full$.bufferToggle(enter$, () => Rx.Observable.timer(2000)).draw('full.bufferToggle(enter, Rx.Observable.timer(2000))', '#container');
full$.windowToggle(enter$, () => Rx.Observable.timer(2000))
.flatMap(window =>
window
.reduce((acc, cur) => acc + parseInt(cur), 0)
).draw('full.windowToggle(enter, Rx.Observable.timer(2000)).flatMap(window => window.reduce(0, (acc, cur) => acc + cur))', '#container');
Rx.Observable.interval(1000).draw('Rx.Observable.interval(1)', '#container');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment