I have a two dimentional array of BehaviorSubject<number>s
. For debugging purposes I want to write the values in a formatted manner as soon as all the array cells emit value. So I wrote this:
Observable.zip(universe.map(row => Observable.zip(row)))
.takeUntil(stopper)
.subscribe(u =>
console.log(`[\n\t[${u.map(r => r.toString()).join("],\n\t[")}]\n]`))
Nothing written. And also this hasn't work:
Observable.zip(universe[0])
.takeUntil(stopper)
.subscribe(u => console.log(`1[${u.toString()}]`))
But these following worked (the array has 5 columns):
Observable.zip(universe[0][0], universe[0][1], universe[0][2], universe[0][3], universe[0][4])
.takeUntil(stopper)
.subscribe(u => console.log(`2[${u.toString()}]`))
Observable.zip(Observable.zip(Observable.zip(Observable.zip(universe[0][0], universe[0][1]), universe[0][2]), universe[0][3]), universe[0][4])
.takeUntil(stopper)
.subscribe(u => console.log(`3[${u.toString()}]`))
Also I have considered .zipAll() operator but there is no document about it.
This may be a bug in Observable.zip() code as it shows ArrayLike<BehaviorSubject<number>>
as possible argument type in code assistance.
So is there any other way to get this functionality? How can I get the array values written down once all of the values are reassigned, without knowing the actual dimensions of course?
The important thing is that zip()
operator doesn't take an array of Observables but an unpacked series of Observables instead.
That's why Observable.zip([obs1, obs2, obs3])
doesn't work.
But Observable.zip(obs1, obs2, obs3)
works.
It's not possible to help you when we don't know what universe
is. From what you have now it seems like you could use destructuring assignment (assuming you're using ES6 or TypeScript):
Observable.zip(...universe[0]);
I don't know what plans are with zipAll()
but right now it just callls zip()
.
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