-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Make #each work with ES6 Maps and Sets #4405
Comments
i'm happy to work on a PR if you feel this is worth doing and also i'm not missing somethign ovious |
welp, #894 pretty much answered it. sorry i didnt see these in my cursory search (which i did do but i admit i didnt look very hard) |
a dev-time instruction telling users to manually spread when they try giving an interable would be very nice tho, if you are interested in a dev-only warning |
@sw-yx & @Conduitry — I took some time to look over the issues you both linked to, and I still think this issue holds some legitimate ground, as Sets and Maps are both considered array-like and can be handled by for…of loops, very similarly (and arguably more performant) than the way the Based on @Rich-Harris's comment on #894, the
If that is true, then why shouldn't it also work for maps and sets. Both are iterable as array-like objects without needing to spread their values to arrays. Both natively support the for…of loops, which works more closely to an actual I created a demo at this REPL. ** NOTE: This REPL only exists to demonstrate that Maps and Sets can be processed by for…of loops and can even support an "index" value as the Here is what that looks like: <script>
export let arrayLike = []; // can be array, set, or map
let i = 0;
for (const item of arrayLike) {
// do something with `item` here
i += 1;
}
</script> I would be happy to work on a PR for this, maybe even in collaboration with @sw-yx (if you're still up for it, Shawn) 👋🏼 |
only if the maintainers want it, which it seems like they dont |
Is your feature request related to a problem? Please describe.
this works
this doesnt work
REPL: https://svelte.dev/repl/06669274098b42b7b5f51a57603cd7d8?version=3.18.2
Describe the solution you'd like
#each
should "just work" with iterablesDescribe alternatives you've considered
do nothing
How important is this feature to you?
medium importance, i feel like svelte should embrace all new js features
The text was updated successfully, but these errors were encountered: