Struct percy_dom::event::VirtualEvents
source · pub struct VirtualEvents { /* private fields */ }
Expand description
When we create a DOM node, we store all of it’s closures and all of it’s children’s closures in VirtualEvents.
When an element gets interacted with in the DOM it’s event handlers get looked up in VirtualEvents.
This helps power event delegation, where for many events kinds of events such as onclick we use a single event listener on the element that the application was mounted on and then as events occur we look up the event handlers in VirtualEvents.
This is faster since instead of needing to add and remove event listeners from the DOM after when applying patches we can simply overwrite the old closures in VirtualEvents with new ones.
Cloning
VirtualEvents can be cloned cheaply. Clones share the same inner data.
Implementations§
source§impl VirtualEvents
impl VirtualEvents
sourcepub fn new() -> VirtualEvents
pub fn new() -> VirtualEvents
Create a new EventsByNodeIdx.
sourcepub fn events_id_props_prefix(&self) -> f64
pub fn events_id_props_prefix(&self) -> f64
Unique for every PercyDom so that if multiple instances of PercyDom are nested their event delegation handlers don’t collide.
sourcepub fn root(&self) -> Rc<RefCell<VirtualEventNode>>
pub fn root(&self) -> Rc<RefCell<VirtualEventNode>>
Get the root event node.
sourcepub fn set_root(&self, root: VirtualEventNode)
pub fn set_root(&self, root: VirtualEventNode)
Set the root event node.
sourcepub fn insert_event(
&self,
events_id: ElementEventsId,
event_name: EventName,
event: EventHandler,
wrapper: Option<Rc<dyn AsRef<JsValue> + 'static>>
)
pub fn insert_event( &self, events_id: ElementEventsId, event_name: EventName, event: EventHandler, wrapper: Option<Rc<dyn AsRef<JsValue> + 'static>> )
Insert a newly tracked event.
Panics
Panics if the event_name is delegated and the event is not, or vice versa.
sourcepub fn overwrite_event_attrib_fn(
&self,
events_id: &ElementEventsId,
event_name: &EventName,
event: EventHandler
)
pub fn overwrite_event_attrib_fn( &self, events_id: &ElementEventsId, event_name: &EventName, event: EventHandler )
sourcepub fn remove_non_delegated_event_wrapper(
&mut self,
events_id: &ElementEventsId,
event_name: &EventName
) -> Rc<dyn AsRef<JsValue> + 'static>
pub fn remove_non_delegated_event_wrapper( &mut self, events_id: &ElementEventsId, event_name: &EventName ) -> Rc<dyn AsRef<JsValue> + 'static>
Remove a managed event.
sourcepub fn get_event_handler(
&self,
events_id: &ElementEventsId,
event_name: &EventName
) -> Option<EventHandler>
pub fn get_event_handler( &self, events_id: &ElementEventsId, event_name: &EventName ) -> Option<EventHandler>
Get the event handler for a node.
sourcepub fn remove_event_handler(
&self,
events_id: &ElementEventsId,
event_name: &EventName
) -> Option<EventHandler>
pub fn remove_event_handler( &self, events_id: &ElementEventsId, event_name: &EventName ) -> Option<EventHandler>
Remove an event handler.
sourcepub fn remove_node(&self, events_id: &ElementEventsId)
pub fn remove_node(&self, events_id: &ElementEventsId)
Remove all event handlers for a node.
sourcepub fn create_element_node(&self) -> VirtualEventNode
pub fn create_element_node(&self) -> VirtualEventNode
Create a new element node.
sourcepub fn create_text_node(&self) -> VirtualEventNode
pub fn create_text_node(&self) -> VirtualEventNode
Create a new element node.
Trait Implementations§
source§impl Clone for VirtualEvents
impl Clone for VirtualEvents
source§fn clone(&self) -> VirtualEvents
fn clone(&self) -> VirtualEvents
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more