Skip to content

A way to spread binds, transitions, actions... #15395

Open
@rChaoz

Description

@rChaoz

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...

<script>
  import { Bind, Transition, Use } from "svelte/symbols"

  const boundProps = $state({ ... })
  const props = {
    [Bind]: boundProps,
    [Transition]: [fade, { duration: 1000 }],
    [Use]: ...
  }
</script>

<Component {...props} />
<!-- Component.svelte -->
<script>
  let { a = 5, b = $bindable(), ...rest } = $props()
</script>

<div {...rest} >
  ...
</div>

where svelte/symbols is something like:

export const Transition = Symbol.for("svelte:transition")
...

I think typescript also plays nice with such symbols.

Importance

nice to have

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions