pub struct EffectRouter<App, RouteSet>where
App: App,{
pub routes: RouteSet,
/* private fields */
}Expand description
Wraps a Core and routes each emitted effect to a type-specific handler.
The router owns the set of routes (RouteSet) and a routing closure which
decides, per effect, which handler should process it. Any follow-up effects
produced while resolving a request are passed back through the same closure,
so routing decisions stay consistent across an entire chain of effects.
Construct one with EffectRouter::new. The router is always held behind an
Arc so that individual routes can keep a Weak reference back to it
and drive the runtime forward when they resolve requests.
Fields§
§routes: RouteSetThe set of handlers effects are routed to.
Exposed so the surrounding FFI type can reach individual routes (for example to resolve a parked or serialized request by id).
Implementations§
Source§impl<App, RouteSet> EffectRouter<App, RouteSet>
impl<App, RouteSet> EffectRouter<App, RouteSet>
Sourcepub fn new<F, R>(core: Core<App>, route_effects_builder: F) -> Arc<Self>
pub fn new<F, R>(core: Core<App>, route_effects_builder: F) -> Arc<Self>
Create a new router wrapping core.
The route set is constructed first (via Routes::new) and then passed
to route_effects_builder, which returns the routing closure. Splitting
construction this way lets the closure capture the routes it needs to
dispatch to, while the routes themselves hold a Weak reference back
to the router so they can resolve requests later.
The router is returned inside an Arc because that shared ownership is
what the routes’ weak references point at; see Arc::new_cyclic.
Sourcepub fn update(&self, event: App::Event)
pub fn update(&self, event: App::Event)
Process an event from the shell and route every resulting effect.
This is the router’s equivalent of Core::process_event: it forwards
the event to the wrapped core and passes each emitted effect through the
routing closure.