-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Passing data into yield blocks #687
Comments
Any reason adding |
Hmm, not sure why I had entirely written off using |
Have to confess the idea of <Outer>
{{foo}}
</Outer>
{{foo}} ...gives me the heebie-jeebies. Perhaps at that point we're better off settling on a way to pass components through as parameters? <!-- App.html -->
<Outer contents={Inner}/>
<!-- Outer.html -->
<div>
<div>Something</div>
<[contents] foo='bar'/>
</div> |
Yeah, I can see As for a way to pass components through parameters ... I'd actually already come up with a sorta-acceptable way to do that as part of my routing library experiment: Have a Also, there's definitely a possibility of an XY problem here - that I have been thinking too narrowly and trying to follow React Router's API, and haven't put in enough time thinking about a more Svelte-friendly way to achieve these broader goals. |
I could see having a built-in way to pass a component though, because currently it's definitely possible from the user side but it requires some boilerplate code that we could move to svelte. |
I would love an in-language way to pass components through parameters. I would hope for it to come with React-like behavior where I could pass in a string (like |
Not sure I follow, can you elaborate? Want to be sure we're on the same page. Though we should probably discuss that on #640 (and maybe close this one, if we're agreed that passing components is the better solution?) |
I just raised a StackOverflow question relating to this topic. Being able to pass components through other components seems to be a very important capability in being able to create abstract and dynamic components which are able to fully hook into the Svelte lifecycle by default. Currently, this seems difficult. |
Will close this in favour of #640, as it seems like that's the best solution to this problem |
I'm working on a little project that may or may not see the light of day, a router inspired by React Router v4. One thing I'm finding I wish Svelte could do is let me pass some data from the nesting component inside its contents, not just from the instantiating component to the contents. This is a little confusing to describe. An example:
App.html
Outer.html
The
{{foo}}
in App.html isundefined
, because it's referring tofoo
in App.html. What I'm looking for is some way to get the value offoo
that's in Outer.html into the yielded contents of the<Outer>
component in App.html.I think the data values that are passed in like this should definitely be explicitly mentioned. One thing I thought of, based on my idea of a
<:Yield/>
tag here, is to have a syntax like<:Yield foo='{{foo}}'/>
instead of{{yield}}
. What I'm not clear on, however, is if App.html also had afoo
whether itsfoo
or Outer.html'sfoo
should take precedence.I'm also not clear on whether this is something we'd want to have, or whether it's something that's practical to implement in Svelte currently. As far as I know, using a
{{yield}}
tag doesn't create another scope/context/state
object, and everything inside<Outer>
is just hooked up to the samestate
as everything outside it is. Implementing something like what I'm describing here would require creating a newstate
, one that's the result of merging two separatestate
s. And then there'd be the question of what happens when someone callsthis.set
inside<Outer>
... whichstate
is updated?This could all turn out to be not worth the effort and complication! Thoughts welcome.
The text was updated successfully, but these errors were encountered: