[−][src]Struct seed::app::App
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]
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
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]
update: UpdateFn<Ms, Mdl, INodes, GMs>,
view: ViewFn<Mdl, INodes>
) -> AppBuilder<Ms, Mdl, INodes, GMs, UndefinedInitAPI>
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]
F: Fn(&Ms) + 'static,
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]
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>>>
Use builder
with AppBuilder::{after_mount, before_mount}
instead.
pub fn run(self) -> Self
[src]
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]
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[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,
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Sealed<T> for T where
T: ?Sized,
T: ?Sized,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,