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

Strange behavior from forkJoin on a Map.prototype.values iterable #4748

Closed
jasonbaker opened this issue Apr 29, 2019 · 4 comments
Closed

Strange behavior from forkJoin on a Map.prototype.values iterable #4748

jasonbaker opened this issue Apr 29, 2019 · 4 comments

Comments

@jasonbaker
Copy link

Bug Report

I'm trying to build a Map where the key is a string and value is an observable. I want to make an Observable that waits on all of the values in this map.

Current Behavior
The behavior seems to be weird whenever you pass in an iterable from Map.prototype.values()

Reproduction

The key part is here:

forkJoin(obsMap.values()).subscribe(x => console.log(x));

This makes the console.log statement log an array that contains a single observable with the last value of the iterable. However, if I plug the iterable into Array.from it works as I'd expect it:

forkJoin(Array.from(obsMap.values())).subscribe(x => console.log(x));

Expected behavior
I'd expect the behavior to be the same for the iterable version and the array version.

Environment

  • Runtime: Chrome 74.0.3729.108
  • RxJS version: 6.4
@kwonoj
Copy link
Member

kwonoj commented Apr 29, 2019

This is due to we expect specific (i.e length property) to determine certain execution paths of given inputs, reason why Array.from will makes this work.

I personally don't have any opinion at this moment if we'd need to support mapiterator for this or not, but curious if other operator we have supports iterables would work same way.

@cartant
Copy link
Collaborator

cartant commented Apr 29, 2019

It's likely that this is related to the problem solved in #4741

@jasonbaker
Copy link
Author

If the code isn't intended to support mapiterator (or other iterators), that may be ok. But if that's the case, I would expect to get an error of some kind that says iterators aren't supported rather than code that silently does the wrong thing and gives a weird resposne.

@cartant
Copy link
Collaborator

cartant commented May 2, 2019

Closing this because this is the expected behaviour. If an array is passed as a single argument, that array is interpreted as the array of observable inputs.

This can be seen in the TypeScript signatures, too.

The behaviour is by-design. However, there is an ongoing discussion about how this sort of thing can rationalised in v7 - so that there are fewer surprises. And I agree with you that, as it is, the API's behaviour is strange.

@cartant cartant closed this as completed May 2, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jun 2, 2019
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

3 participants