The Two Merges
Let's see how we can use merge as a constructor as well as an operator.
We'll cover the following...
The two merges
In the below example, merge
is used as a constructor (a way to create a new observable).
In cases where everything starts at the same time (like the loading bar), merge
used as a constructor is simpler than the operator form.
Press + to interact
merge(...requests).subscribe(val => drawToPage(val),err => alert(err));
However, it’s also an operator:
Press + to interact
let obsOne$ = interval(1000);let obsTwo$ = interval(1500);// Piping through the merge operatorobsOne$.pipe(merge(obsTwo$)).subscribe(console.log);// Is the same as using the merge constructormerge(obsOne$, obsTwo$).subscribe(console.log);
merge
as “operator”
The operator form of merge
comes in handy when you’re in the middle of an observable chain and want to add in more data. ...