seed icon indicating copy to clipboard operation
seed copied to clipboard

Use gloo_events::EventListener

Open platy opened this issue 4 years ago • 1 comments

gloo_events looks like it would make sense in seed as a replacement for some of seed's event management code. Seed is already using gloo_timers and gloo_file, and seed has a stated intention to incorporate gloo crates as they become available.

From a quick look through seed, this would result in:

  • seed::virtual_dom::event_handler_manager::listener:Listener being a little simpler but still keeping it's job of aggregating event handlers and dispatching resulting messages.
  • seed::app::streams::event_stream::EventStream being simpler (maybe very simple)
  • seed::browser::service::routing will have simpler event handling code

Other considerations:

passive

passive is true by default in gloo_events, that would need to be switched false in seed in ev! and raw_ev! in order to use Event.prevent_default (other event macros that don't provide access to web_sys::Event would be passive. This will lead to bad performance in the case of an app intercepting scroll events that use one of these macros

  • automatically set passive = true for scroll events and leave passive = false for others; matching the defaults that browsers use (and matching what seed would provide today, but would mean that seed would need to specify which events default to passive = true rather than the browser)
  • provide a passive_ev! or similar macro for high performance events with passive = true, ev! and raw_ev! would be passive = false

platy avatar Jun 02 '20 09:06 platy

I would like to resolve event API design first: https://github.com/seed-rs/seed/issues/331 (we can integrate passive behavior/switch into it somehow). And then we can focus on implementation details, i.e. rewriting into gloo_events. So I recommend to leave this issue open and return back once new event API is designed/implemented.

MartinKavik avatar Jun 02 '20 10:06 MartinKavik