Skip to content

Instantly share code, notes, and snippets.

@nateabele
Last active September 21, 2016 01:15
Show Gist options
  • Save nateabele/043b434f37a1b313c4676df8567db4a1 to your computer and use it in GitHub Desktop.
Save nateabele/043b434f37a1b313c4676df8567db4a1 to your computer and use it in GitHub Desktop.
Request for feedback on combining multiple observables.
/**
* 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