-
I'm making an app where UI controls are created and placed programmatically from a schema, in a tree fashion arbitrarily deep. I structured the UI into pseudo-widgets, structs where each one has a view() and update() method. The UI is connected to a server which is in charge of processing messages, which can change the state of the UI. For example, when the user clicks on a switch, a message is bubbled up and sent to the server; the server responds with its new internal state that refreshes all the UI. The problem I have is that handling simple updates that require fast visual feedback and no interaction with the server is cumbersome. Each child widget needs to bubble up its message and then it has to be re-routed to the child to reach its update method(), and to do so I need to build a trace of the route. What I would like is custom widget support where each widget can have its own state and can manage its own messages without bubbling up and down the messages. Is there any way of achieving this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Why? The Overall, you should hand-craft the simplest API for the specific use cases of each part of your app. Avoid applying the same design pattern everywhere! If all you have is a hammer, everything looks like a nail. |
Beta Was this translation helpful? Give feedback.
Why? The
Message
,update
,view
triplet introduces the most complexity, you should never use it as a default to design your UI. Instead, you should start with simple view helpers and flat state first!Overall, you should hand-craft the simplest API for the specific use cases of each part of your app. Avoid applying the same design pattern everywhere! If all you have is a hammer, everything looks like a nail.