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

pub struct App<Ms, Mdl, INodes, GMs = UndefinedGMsg> where
    Ms: 'static,
    Mdl: 'static,
    INodes: IntoNodes<Ms>, 
{ pub init_cfg: Option<AppInitCfg<Ms, Mdl, INodes, GMs, dyn IntoAfterMount<Ms, Mdl, INodes, GMs>>>, pub cfg: Rc<AppCfg<Ms, Mdl, INodes, GMs>>, pub data: Rc<AppData<Ms, Mdl>>, }

Fields

init_cfg: Option<AppInitCfg<Ms, Mdl, INodes, GMs, dyn IntoAfterMount<Ms, Mdl, INodes, GMs>>>

Temporary app configuration that is removed after app begins running.

cfg: Rc<AppCfg<Ms, Mdl, INodes, GMs>>

App configuration available for the entire application lifetime.

data: Rc<AppData<Ms, Mdl>>

Mutable app state.

Implementations

impl<Ms, Mdl, INodes: IntoNodes<Ms> + 'static, GMs: 'static> App<Ms, Mdl, INodes, GMs>[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, GMs>) -> Mdl + 'static,
    update: UpdateFn<Ms, Mdl, INodes, GMs>,
    view: ViewFn<Mdl, INodes>
) -> 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 builder(
    update: UpdateFn<Ms, Mdl, INodes, GMs>,
    view: ViewFn<Mdl, INodes>
) -> AppBuilder<Ms, Mdl, INodes, GMs, UndefinedInitAPI>
[src]

Creates a new AppBuilder instance. It's the standard way to create a Seed app.

Then you can call optional builder methods like routes or sink. And you have to call method build_and_start to build and run a new App instance.

NOTE: If your Model doesn't implement Default, you have to call builder method after_mount.

Example

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

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

App::builder(update, view)

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

This runs whenever the state is changed, ie the user-written update function is called. It updates the state, and any DOM elements affected by this change. todo this is where we need to compare against differences and only update nodes affected by the state change.

We re-create the whole virtual dom each time (Is there a way around this? Probably not without knowing what vars the model holds ahead of time), but only edit the rendered, web_sys dom for things that have been changed. We re-render the virtual DOM on every change, but (attempt to) only change the actual DOM, via web_sys, when we need. The model stored in inner is the old model; updated_model is a newly-calculated one.

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

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

pub fn sink(&self, g_msg: GMs)[src]

pub fn process_effect_queue(&self, queue: VecDeque<Effect<Ms, GMs>>)[src]

pub fn patch_window_event_handlers(&self)[src]

pub fn add_message_listener<F>(&self, listener: F) where
    F: Fn(&Ms) + 'static, 
[src]

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

pub fn build(
    init: impl FnOnce(Url, &mut OrdersContainer<Ms, Mdl, INodes, GMs>) -> Init<Mdl> + 'static,
    update: UpdateFn<Ms, Mdl, INodes, GMs>,
    view: ViewFn<Mdl, INodes>
) -> AppBuilder<Ms, Mdl, INodes, GMs, MountPointInitInitAPI<UndefinedMountPoint, BuilderInitFn<Ms, Mdl, INodes, GMs>>>
[src]

Deprecated since 0.5.0:

Use builder with AppBuilder::{after_mount, before_mount} instead.

pub fn run(self) -> Self[src]

Deprecated since 0.4.2:

Please use AppBuilder.build_and_start instead

App initialization: Collect its fundamental components, setup, and perform an initial render.

Trait Implementations

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

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

Auto Trait Implementations

impl<Ms, Mdl, INodes, GMs = UndefinedGMsg> !RefUnwindSafe for App<Ms, Mdl, INodes, GMs>

impl<Ms, Mdl, INodes, GMs = UndefinedGMsg> !Send for App<Ms, Mdl, INodes, GMs>

impl<Ms, Mdl, INodes, GMs = UndefinedGMsg> !Sync for App<Ms, Mdl, INodes, GMs>

impl<Ms, Mdl, INodes, GMs> Unpin for App<Ms, Mdl, INodes, GMs> where
    GMs: Unpin,
    INodes: Unpin,
    Mdl: Unpin,
    Ms: Unpin

impl<Ms, Mdl, INodes, GMs = UndefinedGMsg> !UnwindSafe for App<Ms, Mdl, INodes, GMs>

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> Sealed<T> for T where
    T: ?Sized

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>,