We have been looking at different operators that change the values being emitted. There is another different aspect to streams: what if you need to create a new stream from an existing stream? Another good question is: when does such a situation usually occur? There are plenty of situations, such as:
- Based on a stream of keyUp events, do an AJAX call.
- Count the number of clicks and determine whether the user single, double, or triple-clicked.
You get the idea; we are starting with one type of stream that needs to turn into another type of stream.
Let's first have a look at creating a stream and see what happens when we try to create a stream as the result of using an operator:
let stream$ = Rx.Observable.of(1,2,3)
.map(data => Rx.Observable.of(data));
// Observable, Observable, Observable
stream$.subscribe(data => console.log(data));
At this point...