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

Observable.from should handle "array-like" objects like arguments #1166

Closed
mattpodwysocki opened this issue Jan 12, 2016 · 5 comments
Closed
Labels
help wanted Issues we wouldn't mind assistance with.
Milestone

Comments

@mattpodwysocki
Copy link
Collaborator

In order to be compliant with RxJS v4, Rx.Observable.from is missing the following functionality which brings it on par with Array.from. The current isArray check is too literal and should only check if it has a .length property

// Generate a sequence of numbers
Array.from({length: 5}, (v, k) => k);    
// [0, 1, 2, 3, 4]

And so does RxJS v4:

// Generate a sequence of numbers
Rx.Observable.from({length: 5}, (v, k) => k).subscribe(x => console.log(x));    
// [0, 1, 2, 3, 4]

Filing this bug as I did not see it in the test suite as it is in RxJS v4

@benlesh
Copy link
Member

benlesh commented Jan 12, 2016

That's a horrible way to make a series of numbers. haha. Wouldn't users be better off using range for this? Do we really want them using from like that?

The better reason is so we can handle "array-like" types like arguments... basically anything with this shape:

var arrayLike = {
  "length": "3",
  "0": "foo",
  "1": "bar",
  "2": "baz"
};

So you can do things like Observable.from(arguments)

A better catch is that I don't think we have that result selector implemented.

@benlesh benlesh changed the title Observable.from lacks Observable.from({length: 5}) Observable.from should handle "array-like" objects like arguments Jan 12, 2016
@benlesh benlesh added the help wanted Issues we wouldn't mind assistance with. label Jan 12, 2016
@benlesh
Copy link
Member

benlesh commented Jan 12, 2016

To fix this issue:

  1. To handle array-likes, in particular arguments
  2. To provide an optional resultSelector

@mattpodwysocki
Copy link
Collaborator Author

@Blesh yes, that's not a great example, and no, range won't do it. Instead, focus on array like objects such as any NodeList object to turn into an Observable

@benlesh
Copy link
Member

benlesh commented Feb 9, 2016

I think this is closable as of now. The only hanging issue is defined by the discussion here #1255

@benlesh benlesh closed this as completed Feb 9, 2016
@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
help wanted Issues we wouldn't mind assistance with.
Projects
None yet
Development

No branches or pull requests

2 participants