-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
xilem_core: Refactor Memoization (add Frozen
view, fix force-rebuild in Arc
, and cleanup Memoize
)
#451
xilem_core: Refactor Memoization (add Frozen
view, fix force-rebuild in Arc
, and cleanup Memoize
)
#451
Conversation
xilem_core/src/views/memoize.rs
Outdated
} | ||
|
||
/// Specialized version of [`memoize`], which doesn't take any data at all, the closure is evaluated only once and when a child view forces a rebuild | ||
pub fn static_view<State, Action, Context, Message, V, InitView>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought against this in Bevy, and I'm going to fight against this here; we do not want components to have names ending in _view
.
I know that we can't use static
because that's a keyword. Maybe eternal
works?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eternal
sounds epic at least^^ Yeah I'm also not happy with static_view
ideal would be static
or something. Though eternal
probably suggests that this will live forever...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static
also suggests it will live forever. We definitely can't end up in a state where this is _view
😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also true... Yeah finding good names is hard, probably the hardest thing in programming^^ I'll try to think about it, but I agree, we should remove _view
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, what about frozen
? I've pushed that for now. Other ideas were fixed
, immutable
invariant
(so of course still open for discussion).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like frozen
and immutable
.
fixed
reminds me more of positioning like in CSS position: fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some code style suggestions, actual PR content looks good!
xilem_core/src/views/memoize.rs
Outdated
phantom: PhantomData<fn() -> (State, Action)>, | ||
} | ||
|
||
/// Specialized version of [`memoize`], which doesn't take any data at all, the closure is evaluated only once and when a child view forces a rebuild |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should explain this in terms of why you would use it, not in reference to any other value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably skim again, I also added an example doc-comment for Memoize
Co-authored-by: Daniel McNab <36049421+DJMcNab@users.noreply.github.com>
Static
view, fix force-rebuild in Arc
, and cleanup Memoize
)Frozen
view, fix force-rebuild in Arc
, and cleanup Memoize
)
This adds a
force
which is basically a specializedMemoize
without any bound data.This also cleans up
Memoize
a little bit (mostly code-aesthetic stuff, but also addsState
andAction
params to the view, so that it doesn't offer weird surprises when composing it with views likeAdapt
).The
Arc
view is also fixed, as it didn't support force rebuilding yet, which is relevant for e.g. async, e.g. theMemoizedAwait
view would not work inside anArc<impl View>
currently.