-
-
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
Make equality works on noop callbacks of same type #3430
Conversation
Visit the preview URL for this PR (updated for commit 28fc872): https://yew-rs-api--pr3430-callback-eq-hlry4bwa.web.app (expires Sat, 07 Oct 2023 09:05:48 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 |
Benchmark - SSRYew Master
Pull Request
|
Size Comparison
|
.unwrap() | ||
.clone() | ||
}), | ||
} |
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.
Is there really no other solution other than unwrapping and modifying a HashMap
in a RefCell
? that seems to me like too much work for a Default::default()
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.
Since the function is doing nothing I think it might be possible to do something with unsafe that would be much faster? But I'm really no expert so I won't write that lol
One alternative would be to wrap the Rc into an Option like this:
pub struct Callback<IN, OUT = ()> {
/// A callback which can be called multiple times
pub(crate) cb: Option<Rc<dyn Fn(IN) -> OUT>>,
}
(Or using an enum instead of struct)
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.
But I'm afraid using Option will have a cost at runtime because every call will need to check the option.
What's the rationale behind this? No two closures are the same so why should two callbacks holding different closures be the same? Two Callbacks are the same if they have the same closure and that makes sense to me |
@hamza1311 The case of the noop callback is very particular. Normally we should use Now the thing is that if they write this in their code:
The component will get updated all the time because the callback is re-created every time. |
heh, I just bumped into #3395 and it clearly relates to my story So maybe there is no need for making noop equal to other noops. |
I'm closing this for now because I'm not sure. Anybody can re-open this ticket if they want. |
Description
This make Callbacks NOOP equal to other noops of the exact same type.
Checklist