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