Struct seed::app::App

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

Implementations§

source§

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

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

source

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

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.

source

pub fn update(&self, message: Ms)

Invoke your update function with provided message.

source

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

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.

source

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

source

pub fn notify_with_notification(&self, notification: Notification)

source

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

Trait Implementations§

source§

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

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

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

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

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

§

fn vzip(self) -> V