crux_core

Trait App

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

    // Required methods
    fn update(
        &self,
        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§

source

type Event: 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.

Required Methods§

source

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.

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

Object Safety§

This trait is not object safe.

Implementors§