-
-
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
Spread Props for on:<event> directives #7625
Comments
This is a duplicate of #5112. Keep up with that issue for updates. |
In my use case, I cannot circumvent it with the The ability to Hypothetical proposal:
This pattern of spread events is so frequently encountered, that it may make sense to put it under <Component use:events={$$eventProps}/> |
It is also impossible to pass down actions, binds and style directives. Actually there is no way to pass down any directives. It's not even possible to pass a className from a parent component to a child component. svelte is unfortunately a poorly composable framework. It's hard to write common components like your own |
I agree, the lack of directives spread props, and the inability to pass down dynamic event handlers to child components in any other way is a deal breaker for serious projects. Fortunately for my use case, I'm writing my own compiler on top of Svelte compiler, so there are hacks to work around it. Other things considered, Svelte is such as pleasing disruptive change compared to what you have to do in other frameworks, like React. No more boilerplate reselect memoizers to setup, or manual state management edge cases to fix, especially animations, etc. |
Some work has been done on this, in yet another duplicate thread for this. This PR does not pass all the tests but it does work (for me). Ive done some updates since so this might work for you. Ill get the newer version pushed once Ive got the tests passing. |
Closing as spreading events is supported in Svelte 5 |
Describe the problem
Currently it's possible to spread only non-event props, because
on:
and other directives, such asbind:
, do not work inside a spread object.Example REPL.
Use case: I'm converting an existing application from React that creates UI from JSON files to Svelte. Events, such as
onChange
,onClick
are created dynamically at runtime and passed to components during their render lifecycle using spread props (for encapsulation/abstraction purposes due to recursive nature of the framework).Describe the proposed solution
Enable spread props for all prop directives, including modifiers, so that this code would work:
Alternatives considered
Enable spread props for event bindings without directives
Importance
i cannot use svelte without it
The text was updated successfully, but these errors were encountered: