Merging streams

We've already seen the zip function that merges events one-to-one to create a new stream but there are numerous other ways of combining streams. A very simple example might be a page which has several code paths which all want to perform a similar action. Perhaps we have several actions all of which result in a status message being updated:

var button1 = document.getElementById("button1"); var button2 = document.getElementById("button2"); var button3 = document.getElementById("button3"); var button1Stream = Rx.Observable.fromEvent(button1, 'click'); var button2Stream = Rx.Observable.fromEvent(button2, 'click'); var button3Stream = Rx.Observable.fromEvent(button3, 'click'); var messageStream = Rx.Observable.merge(button1Stream, button2Stream, ...

Get JavaScript: Functional Programming for JavaScript Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.