Last active
February 19, 2019 18:28
-
-
Save kosich/1d6bb94e2122d75fbbc51a52aafa50c7 to your computer and use it in GitHub Desktop.
Pausable Observable that accumulates values. Run at https://observable-playground.github.io/gist/1d6bb94e2122d75fbbc51a52aafa50c7
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
creates a stream that will not emit values until trigger$ emits. | |
then all events from the source$ are emited at once and continue | |
emiting on a normal schedule | |
source$ --0--1---2--------3--4-- | |
trigger$ -----------o------------ | |
0 | |
result$ -----------1-----3--4--- | |
2 |
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, Subject, BehaviorSubject } = require('rxjs/Rx'); | |
const trigger$ = Observable.of('o').delay(10); | |
const source$ = Observable.interval(3).take(5); | |
const afterTrigger$ = source$.skipUntil(trigger$); | |
const result$ = | |
source$ | |
.buffer(trigger$) | |
.take(1) | |
.switchMap(x=>Observable.from(x)) | |
.merge(afterTrigger$); | |
source$.subscribe(rxObserver('source$')); | |
trigger$.subscribe(rxObserver('trigger$')); | |
result$.subscribe(rxObserver('result$')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment