pub struct MvuRuntime<Event, Model, Props, Logic, Render, Spawn>where
Event: EventTrait,
Model: Clone,
Logic: MvuLogic<Event, Model, Props>,
Render: Renderer<Props>,
Spawn: Spawner,{ /* private fields */ }Expand description
The MVU runtime that orchestrates the event loop.
This is the core of the framework. It:
- Initializes the Model and initial Effects via
MvuLogic::init - Processes events through
MvuLogic::update - Reduces the Model to Props via
MvuLogic::view - Delivers Props to the
Rendererfor rendering
The runtime creates a single Emitter that can send events from any thread.
Events are queued via a lock-free MPMC channel and processed on the thread where
MvuRuntime::run was called.
For testing with manual control, use [TestMvuRuntime] with a [crate::TestRenderer].
See the crate-level documentation for a complete example.
§Type Parameters
Event- The event type for your applicationModel- The model/state type for your applicationProps- The props type produced by the view functionLogic- The logic implementation type (implementsMvuLogic)Render- The renderer implementation type (implementsRenderer)Spawn- The spawner implementation type (implementsSpawner)
Implementations§
Source§impl<Event, Model, Props, Logic, Render, Spawn> MvuRuntime<Event, Model, Props, Logic, Render, Spawn>where
Event: EventTrait,
Model: Clone + 'static,
Props: 'static,
Logic: MvuLogic<Event, Model, Props>,
Render: Renderer<Props>,
Spawn: Spawner,
impl<Event, Model, Props, Logic, Render, Spawn> MvuRuntime<Event, Model, Props, Logic, Render, Spawn>where
Event: EventTrait,
Model: Clone + 'static,
Props: 'static,
Logic: MvuLogic<Event, Model, Props>,
Render: Renderer<Props>,
Spawn: Spawner,
Sourcepub fn new(
init_model: Model,
logic: Logic,
renderer: Render,
spawner: Spawn,
) -> Self
pub fn new( init_model: Model, logic: Logic, renderer: Render, spawner: Spawn, ) -> Self
Create a new runtime.
The runtime will not be started until MvuRuntime::run is called.
§Arguments
init_model- The initial statelogic- Application logic implementing MvuLogicrenderer- Platform rendering implementation for rendering Propsspawner- Spawner to execute async effects on your chosen runtime
Sourcepub async fn run(self)
pub async fn run(self)
Initialize the runtime and run the event processing loop.
- Uses the MvuLogic::init function to create and enqueue initial side effects.
- Reduces the initial Model provided at construction to Props via MvuLogic::view.
- Renders the initial Props.
- Processes events from the channel in a loop.
This is an async function that runs the event loop. You can spawn it on your chosen runtime using the spawner, or await it directly.
Events can be emitted from any thread via the Emitter, but are always processed sequentially on the thread where this future is awaited/polled.