-
-
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
[Feature]: Add support of the iterator protocol (es6) for v-for directive (map, weakset, weakmap) #1319
Comments
Does this suggestion break the Vue concept that |
I'd like to see a convincing use case for supporting this because this involves non-trivial addition to the observation mechanism. |
Maybe this helps var array1 = [{a:1},{b:2}];
var set = new Set(array1);
if (Symbol.iterator in set) {
var array2 = Array.from(set);
console.log('array2=', array2); // [{a:1},{b:2}]
}
console.log('array1 === array2', array1 === array2); // false
|
@nervgh these are not use cases. Angular 2 supporting it is cool, but what is a scenario that requires your UI state to be a Set or a Map? |
Closing because:
|
@yyx990803 Here is a valid use case that supports the need for a set.
I don't want the fields to initially be displayed as invalid on the UI, I add a class to show an input as a valid or invalid element. The element is only marked as valid or invalid once it is brought into focus, and marked as touched. I don't want to have a potentially massive array containing all the times an input has been brought into focus, so the Set would be ideal. |
@kyle-mccarthy Why not this? const keys = [
'name',
'email',
'phone',
'company'
]
const data = keys.reduce(
(obj, key) => {...obj, [key]: {val: null, touched: false}},
{}
)
const app = new Vue({
el: '#app-contact',
data: () => data,
computed: {
isValid () {
return {
disabled: keys.map(key => this[key])
.some(field => field.value === null)
}
}
},
methods: {
focused (key) {
this[key].touched=true
},
valid (key) {
const field=this[key]
if (field.touched) {return null}
return field.val !== null && field.val !== ''
}
}
}) |
+1 for implementing this. I have a tree data structure with an iterator, converting to arrays would result in large, unnecessary overhead. |
What's the state of this issue now? |
Maps/Sets are useful stuctures. It's urgent to support them in Vue, otherwise it'll be inefficient to use them in Vue apps. |
very weird issue. If you support Objects then it's only consequent to also support Maps and Sets for exactly the same reason. |
any progress? |
I have a custom collection class, that has an iterator, and I can not loop over it with v-for |
@yyx990803 Iterator protocol isn't just for Set, etc. I want to use flatbuffers for data (which is, of course serializable, as you mentioned that), over which I can use a custom iterator. The point is vue need not be opinionated about in what data structures data is stored, as we have the iterator protocol. |
This is already supported in 2.6. |
Hi
I has modified "Quick example" with using the Iterator protocol.
Will be great if it will work in
1.0
version for es6 environments.Useful links:
https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Iteration_protocols
http://www.2ality.com/2015/02/es6-iteration.html
The text was updated successfully, but these errors were encountered: