-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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 use_raw_ref #3548
Add use_raw_ref #3548
Conversation
21bb4b3
to
cb13baa
Compare
Works like use_mut_ref but doesn't forcibly wrap your type in `RefCell`, so that users can handle more complex or specialized cases of interior mutability.
Benchmark - coreYew Master
Pull Request
|
Visit the preview URL for this PR (updated for commit b0452e7): https://yew-rs--pr3548-use-raw-ref-g8odw0nk.web.app (expires Fri, 17 May 2024 02:15:11 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 |
Benchmark - SSRYew Master
Pull Request
|
Size Comparison
✅ None of the examples has changed their size significantly. |
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'm not sold on the use_raw_ref name but I also can't think of anything better. Going by the name alone, what is the meaning of "raw"? Perhaps we add (back) use_ref
that just returns Rc<T>
and keep use_mut_ref
to avoid a breaking change and provide a convenience hook
Other than that, it looks good.
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.
You are looking for use_memo((), |_| AtomicUsize:::new(0))
?
I was stuck on 0.20 and didn't realize use_ref was renamed in the latest version. |
I'm not really a fan of how Yew currently hides the basic hook functionality and forces you to half-use its convenience hooks for low-level things. Yes, |
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 the iead of reintroducing this hook too. It used to be part of the base set of hooks until #2401 removed it. The reasoning there was to replace this with use_memo((), |_| initializer())
which technically does the same thing. Though as you note use_memo
has two allocations although I'm not sure how much the compiler is able to optimize.
In any case, I think chosing the old name use_ref
would be better because I do not know what "raw" would refer to here - I would have expected some pointer or an internal type, but there are none in the interface.
I have taken the liberty to do the required renaming myself. The failing clippy issue is unrelated (clippy getting smarter every day and catching previously overlooked issues). Not a cause for concern as long as the other tests pass. You will of course still be credited with the PR ;) |
Description
Works like use_mut_ref but doesn't forcibly wrap your type in
RefCell
, so that users can handle more complex or specialized cases of interior mutability.Checklist
use_mut_ref
to use the new hook)