-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
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
Add Iterator supports for v-for #7171
Conversation
添加v-for循环对迭代器的支持
remove semicolon
fixed lint. The array literal notation [] is preferrable no-array-constructor
var to let 一开始是在编译后的文件修改的,不敢使用ES6+的语法,比如for of
let to const
for (i = 0, l = keys.length; i < l; i++) { | ||
key = keys[i] | ||
ret[i] = render(val[key], key, i) | ||
if (keys.length === 0 && val.toString().indexOf('Iterator') > -1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Iterator
looks like new to me. Would you like to give me a link of introduction to Iterator
? I might be wrong but Google only gave me Generator
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Map.prototype.keys() =>return a new Map iterator object.
- Set.prototype.values() => return a new Iterator object containing the values for each element in the given Set, in insertion order.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I have checked the spec and MapIterator's @@toStringTag
symbol returns Map Iterator
. The similar for other iterators.
GIven this, I suspect if a toString
test is legitimate. Checking Symbol.iterator
in proper environment is better, I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the better way is checking Symbol.iterator. At first I thought I can't use the ES6 grammar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Symbol.toStringTag
A string value used for the default description of an object. Used by Object.prototype.toString()
.
Symbol
Iterator can be infinite no? Would that be a problem? |
echo @Gudradain's comment, we need to add a limit to this (maybe with a default value), but the same could go for traditional Array with excessive amount of data (so it's virtually infinite) |
Related: #5893 |
So I have been using the following for a while now: https://github.com/vuejs/vue/blob/cb062c50cdd21628dcf758fe54c84d17d75cb2ca/src/core/instance/render-helpers/render-list.js But I thought that in #5893 it is said that this will not go into core for now? |
I think #8179 is a better implementation of this. Better check for iterator support. |
Thanks for the PR, closing in favor of #8179 due to better support check and tests. |
添加v-for循环对迭代器(Iterator)的支持
What kind of change does this PR introduce? (check at least one)
Does this PR introduce a breaking change? (check one)
If yes, please describe the impact and migration path for existing applications:
The PR fulfills these requirements:
dev
branch for v2.x (or to a previous version branch), not themaster
branchfix #xxx[,#xxx]
, where "xxx" is the issue number)If adding a new feature, the PR's description includes:
Other information: