-
-
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 Other variant to the ListenerKind #2417
Conversation
Visit the preview URL for this PR (updated for commit 3f992d8): https://yew-rs-api--pr2417-other-listener-kind-1itcdlyy.web.app (expires Thu, 03 Feb 2022 19:46:05 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 |
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.
This looks fine. I don't remember when Listener
made this change but I think it used to allow that.
I ran into this problem before and my solution was far more uglier.
Related to #1777
#[allow(non_camel_case_types)] | ||
#[allow(missing_docs)] | ||
pub enum ListenerKind { | ||
$( $kind, )* | ||
other(std::borrow::Cow<'static, str>), |
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 believe we should use proper style for this variant and use upper case Other
. This also conveys that it's different from the other variants.
But given that we're dealing with a special enum, this isn't a blocking issue.
Description
This pull request provides a new listener kind variant so that user-defined listeners can be added to the
VTag
. The newListenerKind::other(Cow<'static, str>)
variant makes possible to implement theListener
trait for a user-defined listener type with a custom event name.This option is very useful for the custom
Html
builders. These are temporary and only used inview
so they can't use thegloo::events::EventListener
. For example, have the following custom event listener:And the MDC widget
TopAppBar
builder using it:It sets the listener for the event with name
"MDCTopAppBar:nav"
insideview
:The full working example: /~https://github.com/noogen-projects/yew-mdc-widgets/blob/master/examples/client/src/main.rs
Checklist
cargo make pr-flow