Closed twop closed 2 years ago
Note that it deviates from dependsOn
, the most usages I saw don't take advantage of first argument being retyped model
. So I think it makes sense to follow Elm here and React (including using the word memo
).
I don't have a super strong opinion on that. For compatibility reasons we can either offer the old signature alongside memo
, or even have just dependsOn
.
I'm closing/reopening the PR to trigger the new CI
For the formatting, I'll add Fantomas in another PR
Fixes https://github.com/TimLariviere/Fabulous-new/issues/18
Intro
This adds support for
View.memo
that can be used to optimize rerendersHere is a minimal usage example (from tests)
Lambda won't be called unless
model.someValue
changes, thus skipping time to renderVerySlowLabel
and diffing itHow it works
Memo Attribute
View.memo
produces a newWidgetBuilder
that captures all needed info in aAttribute
Here is the type definition of the attribute value
Then, to avoid adding any other new properties via
.prop
syntax we wrap the marker type in a new type, like soNote that marker types are needed just for type safety and intellisense, there is no actual instance of
Memoized
ever created.View creation
Then we need to be able to create the underlying control (like XF.Page), how do we do that?
Well, there is a trick I used to achieve that:
We register a new WidgetDefinition that redirects creation to the underlying widget, of course, we need to create it first, like so
Updating the view
Ok, now how to handle updates?
MemoData
(prev vs cur).Easy enough:
So we check if captured types are the same and if they are if the actual keys (the first argument to
View.memo
) are equal.compareAttributes
returnedScalarAttributeComparison.Different
what do we do next?Caveats/Notes
Memoized<'marker>
we need to add one more extension method per collection type, shouldn’t be too bad. Plus it is done either by us (maintainers) or by advanced users of Fabulous. Thus, I feel ok about that.View.memo
, but maybe we should, just to be extra safe. Then we need to add the check intocompareAttributes
functionview
functions. Example: A collection with several children with large number of attributes. You can apply this rulenumber of widgets + number of attributes > 15
(number are aggregate across entire sub tree)