Hello there,
I had a really good - and shockingly productive! - first day with Composer yesterday. Thank you for that. This is fun!
I would now like to get a better understanding of events in composite components. Specifically, I had the need to set an app variable after a tap on a child component.
It seems that (to enforce encapsulation?), logic flows of child components don’t have access to “the outside world,” e.g., to app variables. Only logic flows of the top-level (outermost) component of a composite component do. So, I figured, alright, this makes sense, I’ll simply do this:
- Add an output value to the composite component.
- Set the output value in the child component’s tap handler and then trigger a new tap event in the child after that.
- The tap event triggered by the child would then bubble up to the top level of the composite component.
- At the top level I would have another tap handler, which would grab the output value that was set by the child, and copy it over into my app variable.
Turns out that this almost works. The event that I trigger in the child apparently just cannot be a tap event. It looks like it needs to be a custom event. The following worked:
- At the top level, add a Receive event flow function that listens to Fired from “Trigger event” events.
- In the child component’s tap handler, trigger this event (instead of simply another tap event) after setting the output value.
My questions:
- Am I right in assuming that the only way for child components to send events to the top-level component are custom events, i.e., that standard events like tap won’t work?
- If so, then why does the Trigger event flow function allow me to send a tap event from the child component? What would be a use case for this? I feel like my mental model of events is still a little lacking.
Thanks for any insights you might be able to share!