diff --git a/xilem_web/src/interfaces.rs b/xilem_web/src/interfaces.rs index 99a0dce8b..fff8fcc44 100644 --- a/xilem_web/src/interfaces.rs +++ b/xilem_web/src/interfaces.rs @@ -16,10 +16,8 @@ use std::borrow::Cow; use crate::{ events, - modifiers::{ - Attr, Attributes, Class, ClassIter, Classes, Rotate, Scale, ScaleValue, Style, StyleIter, - Styles, With, - }, + modifiers::{Attr, Class, ClassIter, Rotate, Scale, ScaleValue, Style, StyleIter, With}, + props::{WithElementProps, WithHtmlInputElementProps}, DomNode, DomView, IntoAttributeValue, OptionalAction, Pointer, PointerMsg, }; use wasm_bindgen::JsCast; @@ -51,13 +49,7 @@ macro_rules! event_handler_mixin { } pub trait Element: - Sized - + DomView< - State, - Action, - DomNode: DomNode + With + With> - + AsRef, - > + Sized + DomView + AsRef> { /// Set an attribute for an [`Element`] /// @@ -331,7 +323,7 @@ pub trait Element: impl Element for T where T: DomView, - ::Props: With + With + With, + ::Props: WithElementProps, T::DomNode: AsRef, { } @@ -764,13 +756,7 @@ pub trait HtmlInputElement: HtmlElement< State, Action, - DomNode: DomNode< - Props: With - + With - + With - + With - + With, - > + AsRef, + DomNode: DomNode + AsRef, > { /// See for more details. @@ -857,11 +843,7 @@ impl HtmlInputElement for T where T: HtmlElement, T::DomNode: AsRef, - ::Props: With - + With - + With - + With - + With, + ::Props: WithHtmlInputElementProps, { } diff --git a/xilem_web/src/props/element.rs b/xilem_web/src/props/element.rs index 9ac25fc17..b95f2b89f 100644 --- a/xilem_web/src/props/element.rs +++ b/xilem_web/src/props/element.rs @@ -47,6 +47,7 @@ impl ElementFlags { self.0 |= Self::NEEDS_UPDATE; } } + // Lazy access to attributes etc. to avoid allocating unnecessary memory when it isn't needed // Benchmarks have shown, that this can significantly increase performance and reduce memory usage... /// This holds all the state for a DOM [`Element`](`crate::interfaces::Element`), it is used for [`DomNode::Props`](`crate::DomNode::Props`) @@ -175,3 +176,9 @@ impl With for Element { Modifier::new(modifier, &mut self.flags) } } + +pub trait WithElementProps: + With + With + With + With +{ +} +impl + With + With + With> WithElementProps for T {} diff --git a/xilem_web/src/props/html_input_element.rs b/xilem_web/src/props/html_input_element.rs index b3724a205..210aab0dd 100644 --- a/xilem_web/src/props/html_input_element.rs +++ b/xilem_web/src/props/html_input_element.rs @@ -6,6 +6,8 @@ use crate::modifiers::{Modifier, With}; use crate::{props, FromWithContext, Pod, ViewCtx}; use wasm_bindgen::JsCast as _; +use super::WithElementProps; + /// Props specific to an input element. pub struct HtmlInputElement { element_props: props::Element, @@ -113,3 +115,23 @@ impl With for HtmlInputElement { Modifier::new(&mut self.multiple, &mut self.element_props.flags) } } + +pub trait WithHtmlInputElementProps: + WithElementProps + + With + + With + + With + + With + + With +{ +} +impl< + T: WithElementProps + + With + + With + + With + + With + + With, + > WithHtmlInputElementProps for T +{ +}