pub struct EventAdapter<T> { /* private fields */ }Expand description
Adapts various event value types into an AttributeValue for event attributes.
The html! macro generates EventAdapter::new(expr).into_attribute(event_name)
instead of inline trait dispatch boilerplate. This eliminates the per-attribute-site
generation of __EventWrapper, __IsClosure, __ClosurePicker, __ValuePicker,
__FallbackHelper, and __dispatch types, significantly reducing macro output size.
The adapter pattern handles three cases:
FnMut(NativeEvent)closure →AttributeValue::EventviaNativeEventHandlerNativeEventHandlerdirectly →AttributeValue::Eventas-isOption<NativeEventHandler>→AttributeValue::EventorAttributeValue::Text
Implementations§
Source§impl<T> EventAdapter<T>
impl<T> EventAdapter<T>
pub fn get_mut_inner(&mut self) -> &mut T
Source§impl<T> EventAdapter<T>
impl<T> EventAdapter<T>
Source§impl<F> EventAdapter<F>
Adapts a FnMut(Event) closure into an AttributeValue::Event.
impl<F> EventAdapter<F>
Adapts a FnMut(Event) closure into an AttributeValue::Event.
Wraps the closure into a NativeEventHandler and returns it as an
event attribute value. This replaces the __EventWrapper<F> type
that was previously generated inline by the html! macro.
Sourcepub fn into_attribute(self, event_name: &'static str) -> AttributeValue
pub fn into_attribute(self, event_name: &'static str) -> AttributeValue
Source§impl EventAdapter<NativeEventHandler>
Adapts an owned NativeEventHandler into an AttributeValue::Event directly.
impl EventAdapter<NativeEventHandler>
Adapts an owned NativeEventHandler into an AttributeValue::Event directly.
When the user already provides a NativeEventHandler, the handler is
re-wrapped with the given event_name to ensure the DOM event listener
is bound to the correct event type (e.g., “click” rather than “onclick”).
Sourcepub fn into_attribute(self, event_name: &'static str) -> AttributeValue
pub fn into_attribute(self, event_name: &'static str) -> AttributeValue
Converts the wrapped handler into an event AttributeValue.
Re-wraps the handler with the provided event_name so that the
DOM event listener uses the correct event type string.
§Arguments
&'static str- The event name to bind the handler to.
§Returns
AttributeValue- AnAttributeValue::Eventcontaining the re-wrapped handler.
Source§impl EventAdapter<Option<NativeEventHandler>>
Adapts an Option<NativeEventHandler> into an AttributeValue.
impl EventAdapter<Option<NativeEventHandler>>
Adapts an Option<NativeEventHandler> into an AttributeValue.
Some(handler) becomes AttributeValue::Event(handler) re-wrapped with the
given event name, and None becomes AttributeValue::Text(String::new()).
Sourcepub fn into_attribute(self, event_name: &'static str) -> AttributeValue
pub fn into_attribute(self, event_name: &'static str) -> AttributeValue
Converts the wrapped optional handler into an attribute value.
Re-wraps a Some handler with the provided event_name so that the
DOM event listener uses the correct event type string.
§Arguments
&'static str- The event name to bind the handler to.
§Returns
AttributeValue- An event attribute ifSome, otherwise an empty text attribute.
Source§impl EventAdapter<Option<Rc<dyn Fn(Event)>>>
Adapts an Option<Rc<dyn Fn(Event)>> into an AttributeValue.
impl EventAdapter<Option<Rc<dyn Fn(Event)>>>
Adapts an Option<Rc<dyn Fn(Event)>> into an AttributeValue.
Some(callback) becomes AttributeValue::Event by wrapping the shared closure
into a NativeEventHandler, and None becomes AttributeValue::Text(String::new()).
This supports component Props that use Option<Rc<dyn Fn(Event)>> for event callbacks.