Description
Motivation
Currently, the signature for Widget::update
is:
fn update<C>(self, args: UpdateArgs<Self, C>) -> Option<Self::State>
where C: CharacterCache;
The idea is that you only have to return a new State
if something has changed between updates. This works quite efficiently for small widgets, however can be quite expensive for larger widgets.
A possible solution is to instead return an Option<Box<FnMut(&mut Self::State)>>
. With this change, the Widget::update
signature might look something like this:
fn update<C>(self, args: UpdateArgs<Self, C>) -> Option<Box<FnMut(&mut Self::State)>>
where C: CharacterCache;
This way, instead of returning an entirely new state, we return a function that can mutate the state that already exists, reducing large allocations etc for larger widgets.
Concerns
It would be nice if we didn't have to Box
the function that we're returning, however I'm unsure if it's possible to make an API that doesn't require it (I think we'd need HKT or something).
Any suggestions or alternatives for handling this problem in a nicer way are welcome!