pub struct App { /* private fields */ }Expand description
The Rue application.
Implementations§
Source§impl App
impl App
Sourcepub fn new<F: Fn() -> VNode + 'static>(selector: &str, root_fn: F) -> Self
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.
Sourcepub fn from_component<T: Component>(selector: &str, component: T) -> Self
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()?;Sourcepub fn mount(&mut self) -> Result<(), JsValue>
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.
Sourcepub fn update(&mut self) -> Result<(), JsValue>
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.
Sourcepub fn mount_element(&self) -> Option<&Element>
pub fn mount_element(&self) -> Option<&Element>
Get a reference to the mount element, if mounted.