Repository navigation
Add iterable supports for v-for - #8179
Conversation
|
note: git conflict with #7171 |
|
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? |
| next = iterator.next() | ||
| if (!next.done) { | ||
| key = i | ||
| ret.push(render(next.value, key, i)) |
There was a problem hiding this comment.
Why not just ret.push(render(next.value, ret.length))?
There was a problem hiding this comment.
good point I can update this
I'm aware of this but I think if you choose to implement [Symbol.iterator] you choose to break old browsers compatibility. This way your iterable object has the same behaviour in Vue than in other parts of your code. |
|
I personally like it, I was all for #5893. |
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:
devbranch for v2.x (or to a previous version branch), not themasterbranchfix #xxx[,#xxx], where "xxx" is the issue number)If adding a new feature, the PR's description includes:
Other information:
Adds support for iterable object implementing Symbol.iterator
It shouldn't have an impact for existing code because non iterable objects are not impacted.
Vue will have the same behaviour than a for...of expression for iterables. (actual interest for using iterables)
Allows us to pass an iterable directly to a template without giving internal properties or converting it to an array
I wrote 4 new tests. No existing tests needed changes.
All tests passed. I ran tests with PhantomJS (lack of Symbol support), Firefox and Chrome.