// RxJS v6+import { delay } from'rxjs/operators';import { of, zip } from'rxjs';constsourceOne=of('Hello');constsourceTwo=of('World!');constsourceThree=of('Goodbye');constsourceFour=of('World!');//wait until all observables have emitted a value then emit all as an arrayconstexample=zip( sourceOne,sourceTwo.pipe(delay(1000)),sourceThree.pipe(delay(2000)),sourceFour.pipe(delay(3000)));//output: ["Hello", "World!", "Goodbye", "World!"]constsubscribe=example.subscribe(val =>console.log(val));
// RxJS v6+import { take } from'rxjs/operators';import { interval, zip } from'rxjs';//emit every 1sconstsource=interval(1000);//when one observable completes no more values will be emittedconstexample=zip(source,source.pipe(take(2)));//output: [0,0]...[1,1]constsubscribe=example.subscribe(val =>console.log(val));
Example 3: get X/Y coordinates of drag start/finish (mouse down/up)