pub trait App: Default {
type Event: Unpin + Send + 'static;
type Model: Default;
type ViewModel: Serialize;
type Capabilities;
type Effect: Effect + Unpin;
// Required methods
fn update(
&self,
event: Self::Event,
model: &mut Self::Model,
caps: &Self::Capabilities,
) -> Command<Self::Effect, Self::Event>;
fn view(&self, model: &Self::Model) -> Self::ViewModel;
}
Expand description
Required Associated Types§
Sourcetype Event: Unpin + Send + 'static
type Event: Unpin + Send + 'static
Event, typically an enum
, defines the actions that can be taken to update the application state.
Sourcetype ViewModel: Serialize
type ViewModel: Serialize
ViewModel, typically a struct
describes the user interface that should be
displayed to the user
Sourcetype Capabilities
type Capabilities
Capabilities, typically a struct
, lists the capabilities used by this application
Typically, Capabilities should contain at least an instance of the built-in Render
capability.
Required Methods§
Sourcefn update(
&self,
event: Self::Event,
model: &mut Self::Model,
caps: &Self::Capabilities,
) -> Command<Self::Effect, Self::Event>
fn update( &self, event: Self::Event, model: &mut Self::Model, caps: &Self::Capabilities, ) -> Command<Self::Effect, Self::Event>
Update method defines the transition from one model
state to another in response to an event
.
update
may mutate the model
and returns a Command
describing
the managed side-effects to perform as a result of the event
. Commands can be constructed by capabilities
and combined to run sequentially or concurrently. If migrating from previous version of crux, you
can return Command::done()
for compatibility.
For backwards compatibility, update
may also use the capabilities provided by the caps
argument
to instruct the shell to perform side-effects. The side-effects will run concurrently (capability
calls behave the same as go routines in Go or Promises in JavaScript) with each other and any
effects captured by the returned Command
. Capability calls don’t return anything, but may
take a callback
event which should be dispatched when the effect completes.
Typically, update
should call at least Render::render
.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.