Last active
September 21, 2016 01:15
-
-
Save nateabele/043b434f37a1b313c4676df8567db4a1 to your computer and use it in GitHub Desktop.
Request for feedback on combining multiple observables.
This file contains hidden or 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
/** | |
* This is the simplest way I could think of to consolidate multiple observables such that | |
* (a) subscribers receive the latest value from *all* observables, (b) subscribers are notified | |
* whenever *any* source observable is updated, and (c) new subscribers receive the most current | |
* (consolidated) value. Still seems pretty complicated, so I feel like I must be missing something. | |
*/ | |
var reporter = new ReplaySubject(1); | |
var foo = new ReplaySubject(1); | |
var bar = new ReplaySubject(1); | |
var all = Observable.combineLatest(foo, bar); | |
reporter.subscribe(console.log.bind(console)); | |
all.subscribe(reporter.next.bind(reporter)); | |
foo.next('foo'); | |
bar.next('bar'); | |
// Console: ['foo', 'bar'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment