Migrating from Capabilities to Command
Early versions of Crux performed side-effects through Capabilities: the app
declared a Capabilities type, update took a caps parameter, and
capabilities called back into the app with events. The Command API replaces
all of that. update returns a Command, and the App trait has no
Capabilities type or caps parameter at all.
If you haven't used a version of Crux before 0.17, this guide isn't relevant to you. It is here only for migrating older apps.
The change is a breaking one for any app still on the old API. There are three parts to the migration:
- Remove the
Capabilitiesassociated type and thecapsparameter fromupdate. - Declare the
Effectassociated type on your app. - Return a
Commandfromupdate.
Here's what the end state looks like:
// Rust
impl crux_core::App for App {
type Event = Event;
type Model = Model;
type ViewModel = ViewModel;
type Effect = Effect;
fn update(
&self,
event: Event,
model: &mut Model,
) -> crux_core::Command<Effect, Event> {
crux_core::Command::done() // return a Command
}
}
To begin with, you can return Command::done() (a no-op) from update and
migrate your effect handling to Commands, and to capability APIs that return
command builders, one event at a time. Managed Effects
explains how Commands work.