Struct seed::app::App

source · []
pub struct App<Ms, Mdl, INodes> where
    Ms: 'static,
    Mdl: 'static,
    INodes: IntoNodes<Ms>, 
{ /* private fields */ }

Implementations

We use a struct instead of series of functions, in order to avoid passing repetitive sequences of parameters.

Create, mount and start the App. It’s the standard way to create a Seed app.

NOTE: It tries to hydrate the root element content => you can use it also for prerendered website.

Example
fn init(url: Url, orders: &mut impl Orders<Msg>) -> Model {
    orders
        .subscribe(Msg::UrlChanged)
        .notify(subs::UrlChanged(url));

    Model {
        clicks: 0,
    }
}

fn update(msg: Msg, model: &mut Model, _orders: &mut impl Orders<Msg>) {
  match msg {
      Msg::Clicked => model.clicks += 1,
  }
}

fn view(model: &Model) -> impl IntoNodes<Msg> {
  button![
      format!("Clicked: {}", model.clicks),
      ev(Ev::Click, |_| Msg::Clicked),
  ]
}

#[wasm_bindgen(start)]
pub fn start() {
    // Mount to the root element with id "app".
    // You can pass also `web_sys::Element` or `web_sys::HtmlElement` as a root element.
    // It's NOT recommended to mount into body or into elements which contain scripts.
    App::start("app", init, update, view);
}
Panics

Panics if the root element cannot be found.

Invoke your update function with provided message.

Invoke your update function with provided message.

If the message is None, then your update won’t be invoked, but rerender will be still scheduled.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.