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
Integrating Svelte with certain vanilla JS libraries or components from other systems can be cumbersome due to how only a single component can be defined per file.
Consider e.g. a data table component that allows rendering its cells via callback functions that get passed data which is fetched asynchronously from a server. To use Svelte for rendering the cells, you can define a new component for each cell or bundle all the logic into one component and use an {#if} cascade with some flag that identifies the cell to render.
bind:this would cause the fragment to be compiled to a component that is then assigned to the referenced variable.
let bindings are analogous to props (export let ... ) on regular components
Events forwarded with on:event could be handled on the component instance via $on and the other API instance functions should work the same as for any component if possible
Ideally it would be possible to also use this to just extract elements locally, e.g. if the hierarchy needs to be dynamic but you do not want to separate common parts into extra files, e.g.:
Describe the problem
Integrating Svelte with certain vanilla JS libraries or components from other systems can be cumbersome due to how only a single component can be defined per file.
Consider e.g. a data table component that allows rendering its cells via callback functions that get passed data which is fetched asynchronously from a server. To use Svelte for rendering the cells, you can define a new component for each cell or bundle all the logic into one component and use an
{#if}
cascade with some flag that identifies the cell to render.A hypothetical example:
Describe the proposed solution
Allow defining components within a Svelte file, e.g. by reusing
svelte:fragment
or another special element:bind:this
would cause the fragment to be compiled to a component that is then assigned to the referenced variable.let
bindings are analogous to props (export let ...
) on regular componentson:event
could be handled on the component instance via$on
and the other API instance functions should work the same as for any component if possibleIdeally it would be possible to also use this to just extract elements locally, e.g. if the hierarchy needs to be dynamic but you do not want to separate common parts into extra files, e.g.:
Or maybe it would be possible to assign a
name
so the extra binding andsvelte:component
becomes unnecessary:Alternatives considered
The
{#if}
cascade in a single component is probably the best current workaround if many separate components would have to be created otherwise.For the above example that would be something like:
Importance
would make my life easier
The text was updated successfully, but these errors were encountered: