What is a Model?
A model in Stremio Core is a struct that:- Holds application state
- Implements the
UpdateorUpdateWithCtxtrait - Responds to messages by updating state and returning effects
Core Application Model: Ctx
TheCtx model is the central state container that holds:
Creating a Ctx Instance
Feature Models
Feature models handle specific parts of the application:CatalogWithFilters
Manages catalog browsing with type, catalog, and extra filters:- Generic over content type (MetaItemPreview, Descriptor, etc.)
- Pagination support with lazy loading
- Dynamic filter generation based on installed addons
MetaDetails
Loads and displays detailed information about content:Player
Manages video playback state:State Update Pattern
Models follow a consistent update pattern:1. Match the Message
2. Update State
3. Generate Effects
Composing State Updates
Complex models often delegate to helper functions:Resource Loading Pattern
Many models use theResourceLoadable type to track async operations:
Loading Resources
Handling Async Results
When effects complete, they sendInternal messages back to the model:
State Persistence
TheCtx model persists critical state to storage:
Model Lifecycle
Best Practices
Single Responsibility
Each model should handle one feature or concept
Immutable Messages
Never mutate the message parameter in update functions
Pure Logic
Keep business logic in pure helper functions when possible
Effect Composition
Use
.join() to combine effects from different subsystemsNext Steps
Elm Architecture
Review the Effect, Update, and Msg pattern
Effects and Runtime
Learn how the runtime executes effects
