Skip to content

Tag in element without attribute name should apply its value's properties as attributes #1125

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
PixievoltNo1 opened this issue Jan 24, 2018 · 3 comments

Comments

@PixievoltNo1
Copy link

I'd like to see a template element like <MyComponent {{myObject}}> take all the properties of the tag's value and apply them to the element as attributes, e.g. if myObject is {foo: "mario", bar: "luigi"}, then the element is equivalent to <MyComponent foo="mario" bar="luigi">.

Use cases for this include tree node components, which could specify their children be displayed like so...

{{#each children as childData}}
	<:Self {{childData}}/>
{{/each}}

...and dynamic components, which may need to send arbitary data to their arbitrary component.

<:Component {name} {{data}}/>

I'd be okay with this being forbidden for non-component elements and/or not allowed to mix with any other attributes.

@Conduitry
Copy link
Member

I think this has come up a few times, #195 might be the earliest one. I recall there's been resistance to this feature before (I think from this making it impossible to do certain types of compile-time optimizations?), but I don't remember exactly what the problem was. Probably because it makes it harder to update just the relevant attributes in the child, and to watch just the relevant things in the parent.

@PixievoltNo1
Copy link
Author

Without being familiar with the Svelte codebase, I'd speculate that if we allowed only a property name and not an arbitrary expression, and forbade any other attributes on the element, then it becomes a simple matter of just doing .set(myObject) whenever myObject changes.

At that point, we'd probably need non-double-bracket syntax to keep the double-bracket rules simple, perhaps <MyComponent data:myObject>.

Should I repost the use cases and/or this comment to #195, and let this be closed as a duplicate?

@arxpoetica
Copy link
Member

@PikadudeNo1 I think it's similar enough to #195, yes. Thanks. 👍

7nik pushed a commit to 7nik/svelte that referenced this issue Apr 9, 2025
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

3 participants