You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use snippets programatically by wrapping them inside another snippet via $snippet.
The ability to compose logic related to the snippet and creating adapters for snippets.
Introduction
Snippets are extremely versatile, ergo why they're a strong pattern.
However, a caveat is that you can only provide the snippet with props when you're in control of the @render.
This is fine, as component variables can be declared — however it adds easily 2n lines of code.
<scriptlang='ts'>
import { chevron } from'Icons.svelte'importButtonfrom'Button.svelte'
</script>
<Button>
{#snippeticon()}
{@renderchevron({ rotate: 90 })}
{/snippet}
{#snippetchildren()}
Some text
{/snippet}
</Button>
That's a lot of extra work to provide these parameters.
Today, we can "technically" create snippet adapters via code, however, it's not pretty and messes with Svelte internals.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
$snippet
Use snippets programatically by wrapping them inside another snippet via
$snippet
.The ability to compose logic related to the snippet and creating adapters for snippets.
Introduction
Snippets are extremely versatile, ergo why they're a strong pattern.
However, a caveat is that you can only provide the snippet with props when you're in control of the
@render
.This is fine, as component variables can be declared — however it adds easily 2n lines of code.
That's a lot of extra work to provide these parameters.
Today, we can "technically" create snippet adapters via code, however, it's not pretty and messes with Svelte internals.
Proposal
My proposal here, is to formalize the process of adapting snippets.
Or by code
We could adapt parameters, to fit other ones;
And so.
Tip
Additionally, we could also provide a way to get the
Comment Node
, that the snippet is attached to;as this could be used for tree-crawling
Alternatively, we could allow calling Snippet's outside of the
@render
scope:Now all said and done, this is clearly a nice-to-have, and just an idea. I do personally think it would fit into the Svelte 5 environment.
Beta Was this translation helpful? Give feedback.
All reactions