Hanzhen
07/01/2020, 1:58 PMfunc
instead of class
to create composable elements? func
is lack of the capability of chain calls, for instance: Text("...").font().textColor()
.Adam Powell
07/01/2020, 2:13 PMmolikto
07/01/2020, 2:54 PMAdam Powell
07/01/2020, 3:06 PMAdam Powell
07/01/2020, 3:07 PMHanzhen
07/01/2020, 3:15 PMLeland Richardson [G]
07/01/2020, 3:44 PMComponent
class a long time ago which had a compose
method. It would be similar to flutter widgets or react components.
Eventually we decided to move away from it. The decision took into account a lot of different factors, some talked about above in the thread, but at a really high level one of the ways I looked at it was this:
With a class based API, we were having to place “rules” and “constraints” on all kinds of different programming patterns that were not normal constraints that you would have… for instance, you couldn’t modify properties of the class yourself, you couldn’t hold on to a reference of the class, you couldn’t call its constructor, etc…
This made compose feel less elegant and more like a “square peg in a round hole”.
The decision could be looked at as a decision between “normal rules of functions, but the functions have extra capabilites” or “classes, but with a bunch of extra constraints/rules”.
The former seemed strictly better to me, as it was additive. It also ends up being more ergonomic and fits closer with the mental model of how you should think about a composable widget etc.
There are still some things that classes could have done better, but at the end of the day, I’m really happy with our decision here. It was also later validated more as react came out with react hooks and essentially declared functions as the preferred way of defining react components.Adam Powell
07/01/2020, 3:53 PMandylamax
07/01/2020, 5:01 PMCasey Kulm
07/01/2020, 5:06 PMCasey Kulm
07/01/2020, 5:06 PMFannyDemey
06/06/2022, 11:09 AM