Is controlling snippet props really impossible? #15421
Closed
HighFunctioningSociopathSH
started this conversation in
Ideas
Replies: 1 comment 1 reply
-
This will not work. Having a set number of components at the top level of a snippet is just one very specific case. Snippets can contain element wrappers or dynamic content like Snippets do not store any component information as properties either, they compile to functions that close over everything necessary to construct the snippet. E.g. {#snippet test()}
<div>
<Component {value} />
</div>
<span>Hey</span>
{/snippet} Compiles to something like: var root_1 = $.template(`<div><!></div> <span>Hey</span>`, 1);
// [...]
const test = ($$anchor) => {
var fragment = root_1();
var div = $.first_child(fragment);
var node = $.child(div);
Component(node, { // <- `Component` from outer scope
get value() {
return $.get(value); // <- `value` from outer scope
}
});
$.reset(div);
$.next(2);
$.append($$anchor, fragment);
}; |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm pretty unaware of how svelte actually works under the hood but can't help but ask my question since I feel like it's really needed.
So I would be happy if someone could correct me here.
I was wondering if a
@render
function expects a function that returns 2 methods, render and setup; in which render only returns a raw html and setup is an effect like function that is called with that element's reference; That should mean that when Svelte compiles the children passed to a component and creates the children snippet it should somehow incorporate at least 2 important information inside its setup function. Lets say the children passed was a component, that should mean the component's function and also the props object or proxy (Or a type of Getter function that returns those) was kept somewhere. I assume this because I know If you want to create your own snippet and render a component, you should use the mount or hydrate function inside the setup method and then pass it the element parameter as the target along with the props you want to render your component with. If I'm not wrong, that means the children snippet has these 2 information somewhere in it. Now the big question is, If we were to imagine that the children snippet had a method called data, why can't I callchildren.data
with the expectation that it would return to me an array of objects in which those objects have 2 properties. First the component's function and secondly a function that when called, returns the props object or proxy that was passed to the component.This way I can use
each
inside my component and then render each component while also passing it the user's props.Now instead of being limited to using the
@render
function, I suddenly have control over how many or in which order the children should be rendered, I can even merge props and internal logic with the children passed.And Then the
$effect
functions required to make these components reactive can be created for these just as they would for the rest of the HTML inside the component.Beta Was this translation helpful? Give feedback.
All reactions