-
I have postponed upgrading my Iced dependency for long enough, so this week I started porting my app from Iced 0.4 to 0.9. One of the biggest changes are the new pure widgets and their operations. I wonder why the new widget operations need to be Commands. With impure widgets I could update their state immediately by calling the appropriate function on their State struct, but now the operations return a Command that I need to return from my Anyway, just wondering about the motivations for some of these decisions. No malice intended, still loving Iced <3 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Widget operations are side effects of the
Even if we changed the architecture, operations work on the widget tree and we will always be forced to either returning them or providing a new argument to record them. And even if we wanted to offer a way to execute operations in |
Beta Was this translation helpful? Give feedback.
Widget operations are side effects of the
update
logic. Similar to aCommand
that runs someFuture
.iced
is inspired by Elm, a pure functional language. As a result,iced
follows the Elm Architecture, which exposes side effects as a first-class concept.Even if we changed the architecture, operations work on the widget tree and we will always be forced to either returning them or providing a new argument to record them.
And even if we wanted to offer a way to execute operations in
update
logic itself, this is not possible because operations operate on the result ofview
andview
borrowsself
butupdate
mutatesself
. Because of the borrow rules,update
can never access the result ofview
d…