-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Track children
and parent
within Components
#576
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
Comments
For accessing a child's properties, couldn't you just use the ref? https://svelte.technology/repl?version=1.25.0&gist=ee1e3ef7339bcbb2b6dc322bed7d5ab3 As for accessing the parent, in my opinion that's really really ugly. I think the parent should be the one to allow the child to access their state, which is actually really easy with something like bind: https://svelte.technology/repl?version=1.23.4&gist=ce14b1187c7e2c8a27332e77d226f0b8 |
Suppose I have a If I want to do something with the value of a
It would at least be nice to trigger an event in my Is this currently supported (without using DOM events)? Anway, see also #11 (comment) |
I think there's an issue for sending events to the parent more easily, but I can't quite find it.
100% that's an ugly way to handle it. Basically the situation in this case is that the DataTable and the TableCellInput both share the same state. In my opinion, that's where you start using some sort of shared state library. I suppose a built in way would be to pass a components state among its children, but I could see that being ugly. |
Propagating events between ancestors and descendants (passing along the state info) seems to me to be the most elegant approach.
Propagating events between ancestors and descendants (passing along the state info) seems to me to be the most elegant approach. I definitely don't see how sharing state in yet a different library / component is a better approach! |
These sorts of ideas (if not this specific ticket) have had quite a while to brew now - and I think we're pretty comfortable in our decision to support a parent instance having access to child instances (made more powerful in v3 via dynamic refs) and to not give a child direct access to its parent. Closing. |
So what about my use case (which I'll restate below)?
|
@jslegers The context API is your friend |
(note — that tutorial is currently broken due to a new Mapbox GL version #2297) |
Awesome! Will definitely check that one out next time I give Svelte a try... |
It'd be useful to have access to the children Components from a parent-type. One could easily & directly alter child states (without affecting Parent state).
Similarly, it might be beneficial to add an additional
_parent
key to each component. Doing so allows children to set observers on the parent's state/internal values. Plus it adds an alternative path for communicating between child:parent without the need for custom events.A few days ago, I had a little bit of time to read thru the source. I found that all the
children
data was available here and here during the compilation step. I didn't have enough time to follow up with the output generation. 😿The text was updated successfully, but these errors were encountered: