crux_core

Trait App

Source
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

Implement App on your type to make it into a Crux app. Use your type implementing App as the type argument to Core or Bridge.

Required Associated Types§

Source

type Event: Unpin + Send + 'static

Event, typically an enum, defines the actions that can be taken to update the application state.

Source

type Model: Default

Model, typically a struct defines the internal state of the application

Source

type ViewModel: Serialize

ViewModel, typically a struct describes the user interface that should be displayed to the user

Source

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.

Source

type Effect: Effect + Unpin

Effect, the enum carrying effect requests created by capabilities. Normally this type is derived from Capabilities using the crux_macros::Effect derive macro

Required Methods§

Source

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.

Source

fn view(&self, model: &Self::Model) -> Self::ViewModel

View method is used by the Shell to request the current state of the user interface

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.

Implementors§