Sending events back from components #1027
Replies: 1 comment
-
Personally I like the call methods (or use actions) when communicating from upper to lower layers and send events when communicating from lower to upper layers. It's neat and it aligns to the really simple way to explain things that that: when you tell a component to do something (Action / method call), something happens (Event). More succinctly:
There's no right / best way to architect a Ratatui App. I'd suggest looking at gobang / edma (both similar), heh, xplr / yazi, slumber / openapi-tui, crates-tui, gitui, and pretty much anything in the reverse dependencies list on crates.io for Ratatui (and tui-rs) or the aweseme Ratatui github repo for inspiration. There's also a bunch of info on the website about designing a component approach in the async tutorial and templates. Don't take it as gospel though as many apps have been built that choose different versions of things with the same names. Other sources of ideas for this are looking at the underlying GUI frameworks of operating systems / window managers and seeing how messages (generically actions / events) get passed between types. |
Beta Was this translation helpful? Give feedback.
-
Hello,
I am creating a TUI and wanted to use the component architecture. I looked a lot at gobang and found out that handled events by the components only reply with a
Consumed
state, but I would like to send back events or actions from the components. I for example thought about letting a component switch the component-focus of the app. My event handling is managed by a channel.My first idea is to just return an action from the component event handler and then handle that action after the handled event. I started implementing that idea, but I feel like it gets pretty messy.
My second idea is that each component is able to send events down the event channel, and the actions are just handled as normal events. That would require a bit more work to get the event handler clean into each component, but I feel like it would be a lot more clean.
What are your thoughts about this, or is the idea of components sending actions verbose in itself?
Beta Was this translation helpful? Give feedback.
All reactions