-
-
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
A way to spread binds, transitions, actions... #15395
Comments
Hello, Having a way to set a transition (or animate) on a component would be nice. But for bindings I think this could cause conflicts with the internal stuffs of the component. Also, I think this can be done with anothers parameters of the components instead of props. export default function Component($$anchor, $$props) {
} If we allow special directives on components, we could use a third argument for that : export default function Component($$anchor, $$props, $$directives) {
} And IMHO, I think this need a special syntax, allowing us to separate them from spreading if we dont want to use that. |
Thinking at that, perhaps a solution would be to use something like Exemple : <!-- spread the props -->
<div {...rest}></div>
<!-- spread transitions -->
<div transition:this></div>
<!-- spread animate (must be on the root of the component) -->
<div animate:this></div>
<!-- spread actions -->
<div use:this></div>
<!-- spread props, transitions, animate and actions -->
<div {...rest} transition:this animate:this use:this></div> |
There are a lot of ways to implement this, and there have been many suggestions in the past. The point of this post is that this could be done very similarly to the new attachments, which seems like the current direction. Attachments would also go well together this:
Yes, they'd have to be handled separately.
This was also suggested in the past. I think it has some drawbacks, e.g. how can you tell if a transition is passed, how do you declare in TypeScript if the competent can even receive it. With symbols props, this is really easy: <script lang="ts">
interface Props {
[Transition]: ...
}
// or Pick<HTMLAttributes, Transition, Use, ...>
const { [Transition]: transition }: Props = $props()
if (transition != null) { ... }
</script> |
I think the current way that bindings work (using accessors) is fine, but I do like the idea of using symbols for directives. I think the best way to do that would be a factory for creating keys, so that you can add multiple actions/animations/etc. Example: let props = {
[createActionKey()]:...
[createAnimateKey()]:...
} |
From attachment PR they made attachments symbol so animations and transitions must be contained in attachment symbol because svelte will treat any symbol on element as an attachment... |
Actually, it checks the description of the symbol, so not any symbol will work. |
I keep thinking about #15000, and how the attach is similar to the set if binding to this prop of svelte-element and wondering if there is something there similar for transitions it's just easy access to node ref passed from func param. |
Describe the problem
This has been a common problem in Svelte for long. I like the currently cooking attachments (#15000) PR that aims to solve this, but I think deprecating transitions/other directives won't happen very soon, and a solution for them would be nice.
Describe the proposed solution
Attachments can be applied using symbols. I don't like that any symbol is treated as an attachment - string props are already all used, and using all symbols disallows adding additional stuff in the future. Why not...
where svelte/symbols is something like:
I think typescript also plays nice with such symbols.
Importance
nice to have
The text was updated successfully, but these errors were encountered: