[−][src]Struct savory_html::prelude::ElRef
DOM element reference. You want to use it instead of DOM selectors to get raw DOM elements.
Note: Cloning is cheap, it uses only phantom data and Rc
under the hood.
Example
#[derive(Default)] struct Model { canvas: ElRef<web_sys::HtmlCanvasElement>, } fn view(model: &Model) -> impl IntoNodes<Msg> { canvas![ el_ref(&model.canvas), attrs![ At::Width => px(200), At::Height => px(100), ], ] } fn after_mount(_: Url, orders: &mut impl Orders<Msg>) -> AfterMount<Model> { orders.after_next_render(|_| Msg::Rendered); // ... fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) { match msg { Msg::Rendered => { let canvas = canvas.get().expect("get canvas element"); // ... orders.after_next_render(|_| Msg::Rendered).skip(); } // ...
Fields
Implementations
impl<E> ElRef<E> where
E: Clone + JsCast,
[src]
E: Clone + JsCast,
pub fn new() -> ElRef<E>
[src]
pub fn get(&self) -> Option<E>
[src]
Get referenced DOM element.
It returns Some(element)
when:
- An associated DOM element has been already attached during render.
- The DOM element is still a part of the current DOM.
- The DOM element has the same type like
ElRef
.
pub fn map_type<T>(&self) -> ElRef<T>
[src]
Map ElRef
type.
-
It just changes type saved in the phantom - it's cheap.
-
It's useful when you have, for instance,
ElRef<HtmlInputElement>
and want to focus the referenced input.HtmlInputElement
doesn't have methodfocus
, but parent interfaceHtmlElement
has.
Example
let input: ElRef<HtmlInputElement> = model.refs.my_input.clone(); orders.after_next_render(move |_| { input .map_type::<HtmlElement>() .get() .expect("get `my_input`") .focus() .expect("focus 'my_input'"); });
Trait Implementations
impl<E> Clone for ElRef<E> where
E: Clone,
[src]
E: Clone,
impl<E> Debug for ElRef<E> where
E: Debug,
[src]
E: Debug,
impl<E> Default for ElRef<E>
[src]
impl<T: Clone + JsCast> ElRefExt<T> for ElRef<T>
[src]
impl<Ms, E> UpdateEl<Ms> for ElRef<E> where
E: Clone,
[src]
E: Clone,
Auto Trait Implementations
impl<E> !RefUnwindSafe for ElRef<E>
impl<E> !Send for ElRef<E>
impl<E> !Sync for ElRef<E>
impl<E> Unpin for ElRef<E> where
E: Unpin,
E: Unpin,
impl<E> !UnwindSafe for ElRef<E>
Blanket Implementations
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S where
D: AdaptFrom<S, Swp, Dwp, T>,
Dwp: WhitePoint,
Swp: WhitePoint,
T: Component + Float,
[src]
D: AdaptFrom<S, Swp, Dwp, T>,
Dwp: WhitePoint,
Swp: WhitePoint,
T: Component + Float,
fn adapt_into_using<M>(self, method: M) -> D where
M: TransformMatrix<Swp, Dwp, T>,
[src]
M: TransformMatrix<Swp, Dwp, T>,
fn adapt_into(self) -> D
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Sealed<T> for T where
T: ?Sized,
T: ?Sized,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,