compose method and yields #3698
-
I am evaluating textual for a project I need to implement at work. I have a very lightweight understanding of it, but something that just rubs the wrong way from the design point of view is the compose() method and the large need to write the layout of the view as a set of yield/with statements, rather than a widget tree. Is there any actual advantage to this approach, and is there a way to define the view in a way that does not require yield/with logic for each little component of the view? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
How do you envisage this working/looking? Note that container widgets generally take the list of children as a parameter, and with Parent():
with Child():
yield Grandchild() as: return [Parent(Child(Grandchild()))] |
Beta Was this translation helpful? Give feedback.
The generator approach is more expressive, and easier to edit. The natural indentation of the with block expresses nesting without the need for so much parenthesis. It also allows you to express dynamic constructs more naturally.
Adding logic is quite natural with the generator approach, but more awkward with a list.
But all that is required is for it to return an iterable of Widgets. So as @davep pointed out, you are free to return a list.