I have an array of observables and want to pass to Rx.Observable.zip
. I tried and it does not get subscribed at all.
Code snippet(just am example):
const sourceOne = Rx.Observable.of('Hello');
const sourceTwo = Rx.Observable.of('World!');
const sourceThree = Rx.Observable.of('Goodbye');
const sourceFour = Rx.Observable.of('World!');
const arr$ = [sourceOne, sourceTwo, sourceThree, sourceFour];
const zip$ = (a$) => Rx.Observable.zip(a$);
const subscribe = zip$(arr$).subscribe(val => console.log(val));
Is there a way to pass an array to Rx.Observable.zip
?
Operator zip
accepts only an unpacked array.
zip(sourceOne, sourceTwo, sourceThree, ...);
If you're using ES6 you can also use destructuring assignment with ...
:
const zip$ = (a$) => zip(...arr$);
See live demo: https://jsbin.com/tinaxeq/1/edit?js,console
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With