Skip to main content

App

Struct App 

Source
pub struct App { /* private fields */ }
Expand description

The Rue application.

Implementations§

Source§

impl App

Source

pub fn new<F: Fn() -> VNode + 'static>(selector: &str, root_fn: F) -> Self

Create a new application from a render closure.

This is the low-level constructor. Prefer App::from_component for lifecycle-managed components.

Source

pub fn from_component<T: Component>(selector: &str, component: T) -> Self

Create a new application from a Component.

This will call Component::init() once, then use Component::render() for every render cycle. After the first mount, Component::mounted() is called. Before each update, Component::should_update() is checked.

§Example
let app = App::from_component("#app", MyComponent::new());
app.mount()?;
Source

pub fn mount(&mut self) -> Result<(), JsValue>

Mount the application to the DOM.

Renders the initial VNode tree, inserts it into the mount point, and calls Component::mounted() if a component was provided.

Source

pub fn update(&mut self) -> Result<(), JsValue>

Update the application by diffing the old and new VNode trees and applying only the necessary changes to the DOM.

Before re-rendering, calls Component::should_update() if a component was provided. Skips the update if it returns false.

Unlike the previous naive implementation (which destroyed and recreated all DOM nodes), this preserves scroll position, input focus, and form state for unchanged elements.

Source

pub fn mount_element(&self) -> Option<&Element>

Get a reference to the mount element, if mounted.

Auto Trait Implementations§

§

impl Freeze for App

§

impl !RefUnwindSafe for App

§

impl !Send for App

§

impl !Sync for App

§

impl Unpin for App

§

impl UnsafeUnpin for App

§

impl !UnwindSafe for App

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more