Trait crux_core::App

source ·
pub trait App: Default {
    type Event: Send + 'static;
    type Model: Default;
    type ViewModel: Serialize;
    type Capabilities;

    // Required methods
    fn update(
        event: Self::Event,
        model: &mut Self::Model,
        caps: &Self::Capabilities
    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§


type Event: Send + 'static

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


type Model: Default

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


type ViewModel: Serialize

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


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§


fn update( &self, event: Self::Event, model: &mut Self::Model, caps: &Self::Capabilities )

Update method defines the transition from one model state to another in response to an event.

Update function can mutate the model and 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). 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.


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

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

Object Safety§

This trait is not object safe.