-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Self-references/partials #51
Comments
Does it mean that something like this:
making it work like this:
|
Is a special construct really needed for this? It looks like we could use the component recursively as long as the compiler added a self-reference in its const MyComponent = { components: {} };
MyComponent.components.MyComponent = realMyComponent;
export default MyComponent; {{if recurse}}
<MyComponent/>
{{/if}} I think something along these lines should work, and it'd be closer to native Custom Elements behavior. |
So, something like a tree-view would become possible by using two components, one for the tree node and one for the tree itself, similar to this example in Vue. For something like a tree-view, being able to put both the node and root views/components in the same file makes a lot of sense though - in fact, keeping the node component itself as a private component of the tree-view itself would make a lot of sense. What I would like is for the |
Thanks for the feedback everyone — finally got round to tackling this, have opened #332. @mrkishi Unfortunately that wouldn't work as you can't export a reference, you have to export an object literal. That's so that Svelte can do static analysis on your component at compile time. @mindplay-dk The root and the nodes would have to be two separate components, but that's ok since the node would only depend on itself |
Released in 1.10.0. You can see it in action on Svelte Hacker News, by clicking on a comment thread (comments embed their children recursively) |
Feels incredibly fast! Excited to test this out :-) |
An interesting point raised in this article – how can you have tree-like structures without hardcoding the depth of the tree?
Certainly should be possible within Svelte's architecture – possibly using a partial or maybe some sigil that causes the component to render itself (
<@Self nodes='{{child.nodes}}'/>
, or something)The text was updated successfully, but these errors were encountered: