Core Concepts
The Elm Architecture has three main components:- Model: The state of your application
- Messages: Events that describe state changes
- Update: A function that produces new state and effects
The Msg Type
Messages are the only way to change state in Stremio Core. Every user interaction, API response, or timer event becomes a message:Action Messages
Actions are dispatched by the application UI:Internal Messages
Internal messages are used for state transitions that don’t come from user actions:Event Messages
Events are emitted to the UI to notify about important state changes:The Update Trait
TheUpdate trait defines how models respond to messages:
UpdateWithCtx:
Update Implementation Example
Here’s how theCtx model handles authentication:
Effects
Effects represent asynchronous operations or additional messages to process:Creating Effects
TheEffects builder provides convenient methods:
The unchanged() Method
Effects track whether the model state changed:has_changed is true, the runtime emits a NewState event to notify the UI. Use .unchanged() when effects don’t modify the model:
Example: CatalogWithFilters Update
Here’s a complete example from the catalog model:Benefits of This Pattern
Predictability
All state changes go through update functions, making the data flow easy to trace.
Testability
Update functions are pure (except for effects), making them easy to test.
Composability
Effects can be combined using
.join(), making complex updates manageable.Type Safety
The compiler ensures all messages are handled correctly.
Next Steps
Models and State
Learn how models manage application state
Effects and Runtime
Understand how effects are executed
