-
-
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
Remove InputData & ChangeData #2000
Conversation
InputData and ChangeData have been removed as they were overly restrictive, the implementation would only allow adding listeners to input, textarea, or select elements and would panic at runtime otherwise. TypedTarget trait should help with migration for getting the value from inputs etc. The user is much more likely to know what the target type is and this saves Yew trying to brute force what element the target type might be. This is convenient enough trait but follows the same theme of JsCast which might also be a nice way for new users to be introduced to what JsCast can do at a limited scope.
Updated to use the TypedTarget trait on event's where a value is required from the target of an event. Fixed instances where the `value` attribute is applied when this is not required to do so, this reduces rendering on some examples. Fixed using string values when floats are required, as the new approach allows for calling HtmlInputElement::value_as_number.
Visit the preview URL for this PR (updated for commit a3733c7): https://yew-rs--pr2000-target-cast-v5z5x783.web.app (expires Sat, 21 Aug 2021 13:06:55 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 |
Event targets are of type `EventTarget` and this should be the minimum bounds for `TargetCast`.
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.
Can you add an example using this with CustomEvent
So add a new example to the examples? for creating and dispatching a |
I'm not sure if it should be a new example. Maybe we can add a snippet in API docs? |
As in docs.rs or the website? |
docs.rs |
Just realised that Yew doesn't enable the |
It's fine as-is then. We don't really need to enable the feature just for the snippet, especially since it'll be just like the other events |
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.
LGTM
Description
InputData
andChangeData
have been removed as they were overlyrestrictive, the implementation would only allow adding listeners to
input
,textarea
, orselect
elements and would panic at runtimeotherwise.
TargetCast
TraitIt's one implementation
TargetCast
trait should help with migration and getting the value frominputs etc. It is implemented for every
web_sys
Event which makes ituseful beyond what
InputData
andChangeData
provided.The user is much more likely to know what the target type is
and this saves Yew trying to brute force what element the target type might
be. This also allows users to cast to custom web component types when they
extend
EventTarget
(which is easily done in wasm_bindgen).I think this trait is convenient enough to exist on it's own but follows the
same theme of
JsCast
which might also be a nice way for new users tobe introduced to what
JsCast
can do at a limited scope.Updated the examples to use the
TargetCast
trait on event's where a value isrequired from the target of an event.
Fixed instances where the
value
attribute is applied when this is notrequired to do so, this reduces rendering on some examples.
Fixed using string values when floats are required, as the new approach allows for calling
HtmlInputElement::value_as_number
.Examples
TargetCast::target_dyn_into
TargetCast::target_unchecked_into
It might be useful to add a util fn for getting and setting the
value
property but I think this is a more global concern then events even so I'd propose doing this, if wanted, in another PR.Fixes #1776
Checklist
cargo make pr-flow