pub struct App<Ms, Mdl, INodes> where
Ms: 'static,
Mdl: 'static,
INodes: IntoNodes<Ms>, { /* private fields */ }
Implementations
sourceimpl<Ms, Mdl, INodes> App<Ms, Mdl, INodes> where
INodes: IntoNodes<Ms> + 'static,
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.
sourcepub 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
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.
sourcepub fn update_with_option(&self, message: Option<Ms>)
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.
pub fn notify<SubMs: 'static + Any + Clone>(&self, message: SubMs)
pub fn notify_with_notification(&self, notification: Notification)
pub fn mailbox(&self) -> Mailbox<Ms>
Trait Implementations
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more