-
-
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
Allow skipping a callback when reforming #2864
Conversation
Size Comparison
✅ None of the examples has changed their size significantly. |
4ca6673
to
7c57013
Compare
Visit the preview URL for this PR (updated for commit 041e4bb): https://yew-rs-api--pr2864-feature-ext-callback-gglmhxo5.web.app (expires Mon, 19 Sep 2022 11:59:02 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 |
Benchmark - SSRYew Master
Pull Request
|
7c57013
to
3259383
Compare
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.
One suggestion to the documentation, feel free to suggest an even better one.
The test cases seem fine, and the method has a clear purpose to me.
packages/yew/src/callback.rs
Outdated
/// Creates a new callback from another callback and a function | ||
/// That when emitted will call that function and will emit the original callback if it is | ||
/// not `None`. | ||
pub fn filter_reform<F, T>(&self, func: F) -> Callback<T> |
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.
One thing I almost forgot: Would it make sense to have this return Callback<T, Option<OUT>>
instead - and generalize for any Callback<IN, OUT>
?
EDIT: If returning Option<OUT>
is not desirable, perhaps requiring OUT: Default
and keeping the same OUT
as its output makes most sense.
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.
Hm, that sounds like an interesting idea. I will try to amend the PR with this.
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.
Looks good. I amended the PR.
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.
Looks good. Thanks for also improving callback test coverage
Seems like failed test are related to tokio-rs/tokio#4973. Can you update the Cargo.toml to pin tokio to a working version? That should make a CI green
This adds a method to the callback, similar to Rust's filter_map, which allows to reform a callback, but also suppress the emit in case the reform function returns `None`.
Co-authored-by: WorldSEnder <[email protected]>
As suggested in the PR, this implements filter_reform for all output types of callbacks by mapping to `Option<OUT>`.
4846d36
to
291beaf
Compare
Although I believe that the code is more readable/understandable with an explicit map, I am not sure adding a clippy exception just for that is justified. So I applied the clippy suggestion.
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.
Thanks for the PR. 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.
Looks good. This method has a clear use case and is a welcome addition.
Thanks for the PR!
Description
This adds a method to the callback, similar to Rust's filter_map, which allows to reform a callback, but also suppress the emit in case the reform function returns
None
.Checklist