Skip to content
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

Access to Events in handlers (virtual DOM) #44

Closed
agrif opened this issue Nov 21, 2018 · 3 comments
Closed

Access to Events in handlers (virtual DOM) #44

agrif opened this issue Nov 21, 2018 · 3 comments

Comments

@agrif
Copy link
Contributor

agrif commented Nov 21, 2018

Unless I'm mistaken, there isn't currently any way to access the event itself inside event handlers.

It looks like some support for this was added recently for oninput, and I think that route is maybe a bit labor intensive but worth pursuing.

However, in the meantime, would it be possible to let generic handlers access their event? Either as a Event struct, or an even more generic JsValue. This maybe isn't a very pleasant API, but it would be a quick win, and let us actually inspect the events for things like keycodes that aren't available any other way.

@chinedufn
Copy link
Owner

I’m on mobile for the weekend so forgive any typos

So the !myevent closure would have one Event parameter and then you could just convert it into any other type of event that you wanted?

That makes a lot of sense to me and I a pretty quick win.

We’d just need to update https://github.com/chinedufn/percy/blob/master/crates/virtual-node/src/lib.rs#L386 to be FnMut(Event)

Interested in taking a stab at this? I’d be happy to answer any questions!

Otherwise I should be back to my machine later this weekend and I can take a look!

@agrif
Copy link
Contributor Author

agrif commented Nov 22, 2018

I'll give it a look, but I'm working on some other things right now too. If you find the time first, go on ahead!

agrif added a commit to agrif/percy that referenced this issue Nov 24, 2018
@agrif agrif closed this as completed Nov 27, 2018
@chinedufn
Copy link
Owner

chinedufn commented Jan 19, 2019

@agrif thanks for raising the issue!

You can now you any web_sys::* event that you please. Ended up just storing the Closure's dynamically with some help from rustwasm/wasm-bindgen#1140 (comment)

Commit -> ab4e8c3

example:

html! { <div !onclick=|ev: web_sys::MouseEvent| {}></div> }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants