[][src]Struct seed::app::App

pub struct App<Ms, Mdl, INodes> where
    Ms: 'static,
    Mdl: 'static,
    INodes: IntoNodes<Ms>, 
{ /* fields omitted */ }

Implementations

impl<Ms, Mdl, INodes> App<Ms, Mdl, INodes> where
    INodes: IntoNodes<Ms> + 'static, 
[src]

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

pub fn start(
    root_element: impl GetElement,
    init: impl FnOnce(Url, &mut OrdersContainer<Ms, Mdl, INodes>) -> Mdl + 'static,
    update: impl FnOnce(Ms, &mut Mdl, &mut OrdersContainer<Ms, Mdl, INodes>) + Clone + 'static,
    view: impl FnOnce(&Mdl) -> INodes + Clone + 'static
) -> Self
[src]

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.

pub fn update(&self, message: Ms)[src]

Invoke your update function with provided message.

pub fn update_with_option(&self, message: Option<Ms>)[src]

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.

pub fn notify<SubMs: 'static + Any + Clone>(&self, message: SubMs)[src]

pub fn notify_with_notification(&self, notification: Notification)[src]

pub fn mailbox(&self) -> Mailbox<Ms>[src]

Trait Implementations

impl<Ms, Mdl, INodes> Clone for App<Ms, Mdl, INodes> where
    INodes: IntoNodes<Ms>, 
[src]

impl<Ms, Mdl, INodes> Debug for App<Ms, Mdl, INodes> where
    Ms: 'static,
    Mdl: 'static,
    INodes: IntoNodes<Ms>, 
[src]

Auto Trait Implementations

impl<Ms, Mdl, INodes> !RefUnwindSafe for App<Ms, Mdl, INodes>

impl<Ms, Mdl, INodes> !Send for App<Ms, Mdl, INodes>

impl<Ms, Mdl, INodes> !Sync for App<Ms, Mdl, INodes>

impl<Ms, Mdl, INodes> Unpin for App<Ms, Mdl, INodes>

impl<Ms, Mdl, INodes> !UnwindSafe for App<Ms, Mdl, INodes>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,