Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

combineAll does not emit on empty array #1910

Closed
marcusradell opened this issue Aug 30, 2016 · 4 comments
Closed

combineAll does not emit on empty array #1910

marcusradell opened this issue Aug 30, 2016 · 4 comments

Comments

@marcusradell
Copy link
Contributor

Using rxjsv5 combineAll, I have an issue forming a state tree of children states.

If I have an array of state streams, I can get the state data in an array corresponding to the streams. But if I switchMap from an array with n state streams to an array with zero state streams (empty array), combineAll will not emit anything.

This makes the app state tree contain the old state data of the last non-empty array of state streams.
I have fixed it right now by mapping the array of state streams to always concat a dummy stream with a dummy value, which is really confusing for other developers looking at the code and state tree.

@trxcllnt
Copy link
Member

combineAll won't emit unless the combined Observables emit at least one value, but you could check to ensure the collection you're combining is empty or not, and either combine or emit an empty Array:

var arrayOfStreamsStream = Rx.Observable
    .of(
        [], [
            Rx.Observable.of('blah-1'), // component state.
            Rx.Observable.of('blah-2'),
            Rx.Observable.of('blah-3')
        ], [], [
            Rx.Observable.of('foo-1'),
            Rx.Observable.of('qux-2')
        ]
    )
    .switchMap(function onMap(coll) {
        return coll.length === 0 ?
            Observable.of(coll) :
            Observable.combineLatest(...coll);
    })
    .subscribe(function onSubscribe(data) {
        console.log('onSubscribe START')
        console.dir(data)
        console.log('onSubscribe END')
    })

@marcusradell
Copy link
Contributor Author

I will totally accept that as a good solution! Many thanks.

Please post to Stackoverflow if you'd like an accepted answer, or tell me otherwise so I can post it and close that one.

@marcusradell
Copy link
Contributor Author

Wrote the answer on SO.

@lock
Copy link

lock bot commented Jun 7, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants