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

source

pub fn new() -> VirtualEvents

Create a new EventsByNodeIdx.

source

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.

source

pub fn root(&self) -> Rc<RefCell<VirtualEventNode>>

Get the root event node.

source

pub fn set_root(&self, root: VirtualEventNode)

Set the root event node.

source

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.

source

pub fn overwrite_event_attrib_fn( &self, events_id: &ElementEventsId, event_name: &EventName, event: EventHandler )

Overwrite an event handler.

Panics

Panics if there isn’t an event attrib fn to overwrite.

source

pub fn remove_non_delegated_event_wrapper( &mut self, events_id: &ElementEventsId, event_name: &EventName ) -> Rc<dyn AsRef<JsValue> + 'static>

Remove a managed event.

source

pub fn get_event_handler( &self, events_id: &ElementEventsId, event_name: &EventName ) -> Option<EventHandler>

Get the event handler for a node.

source

pub fn remove_event_handler( &self, events_id: &ElementEventsId, event_name: &EventName ) -> Option<EventHandler>

Remove an event handler.

source

pub fn remove_node(&self, events_id: &ElementEventsId)

Remove all event handlers for a node.

source

pub fn create_element_node(&self) -> VirtualEventNode

Create a new element node.

source

pub fn create_text_node(&self) -> VirtualEventNode

Create a new element node.

Trait Implementations§

source§

impl Clone for VirtualEvents

source§

fn clone(&self) -> VirtualEvents

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.