-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Add new
and map
methods to Ref
#8797
Conversation
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.
Just a few nitpicks, but looks good overall!
Co-authored-by: Gino Valente <[email protected]>
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.
Great docs, well-motivated. Code is correct.
value: f(self.value), | ||
ticks: self.ticks, | ||
} | ||
} |
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.
Mind adding an extra empty line to separate these new functions.
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.
done
Objective
Ref
is a useful way of accessing change detection data.However, unlike
Mut
, it doesn't expose a constructor or even a way to go fromRef<A>
toRef<B>
.Such methods could be useful, for example, to 3rd party crates that want to expose change detection information in a clean way.
My use case is to map a
Ref<T>
into aRef<dyn Reflect>
, and keep change detection info to avoid running expansive routines.Solution
We add the
new
andmap
methods. Since similar methods exist onMut
where they are much more footgunny to use, I judged that it was acceptable to create such methods.Workaround
Currently, it's not possible to create/project
Ref
s. One can define their ownRef
and implementChangeDetection
on it. One would then useChangeTrackers
to populate the customRef
with tick data.Changelog
Ref::map
andRef::new
methods for more ergonomicRef
s