Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Introduce .from static method, deprecate #toAnyCollection methods #1358

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

Closed
avocadowastaken opened this issue Oct 5, 2017 · 2 comments
Closed

Comments

@avocadowastaken
Copy link
Contributor

I like the way Array.from works. It takes any iterable and casts it to array.

As discussed in #317 - we have to deprecate toMap, toList, and etc. methods, but we also need a good replacement for it.

We can do this in constructors - but immutable class constructors returns values in it, which is restricted in es6 classes spec and sooner or later people will start to demand untranspiled ES6 module version for modern browsers.

And as a summary:

  1. Implement #from(iterable) for each method.
  2. Add deprecation warnings for toCollection methods.
@leebyron
Copy link
Collaborator

leebyron commented Oct 5, 2017

Is there an example of a collection that does not already accept an iterable in this way? If I recall, Array.from was added because new Array() takes arguments in a weird way and changing that would have broken the internet so TC39 just added a new method instead. Contrast that with ES6 Map and Set which do not have .from() methods, but who's constructor functions have the same contract of accepting an iterable.

@avocadowastaken
Copy link
Contributor Author

Yeah you're right, I was thinking about replacement for toCollection and problem with constructors in ES6 and came up with this idea.

Anyways, thanks for quick response, I would love to work on this direction.
Main idea I was thinking about is - optimization for better tree shaking and circular deps with static methods are main issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants