reactive_graph_plugin_api/behaviours/relations/
relation_component_behaviour_registry.rs

1use std::ops::Deref;
2use std::sync::Arc;
3
4use async_trait::async_trait;
5use tokio_stream::StreamExt;
6
7use reactive_graph_behaviour_model_api::prelude::*;
8
9use reactive_graph_graph::RelationInstanceId;
10use reactive_graph_reactive_model_impl::ReactiveRelation;
11
12#[async_trait]
13pub trait RelationComponentBehaviourRegistry: Send + Sync {
14    /// Registers a factory for creating relation component behaviours.
15    /// If a relation instance has the given component then the given behaviour is applied.
16    /// The behaviour will be created using the given RelationBehaviourCreator.
17    #[allow(unused_variables)]
18    async fn register(
19        &self,
20        component_behaviour_ty: ComponentBehaviourTypeId,
21        factory: Arc<dyn BehaviourFactory<RelationInstanceId, ReactiveRelation> + Send + Sync>,
22    );
23
24    async fn register_all(&self, factories: &BehaviourFactories<RelationInstanceId, ReactiveRelation>) {
25        let mut factories = tokio_stream::iter(factories.deref().clone());
26        while let Some((ty, factory)) = factories.next().await {
27            self.register(ComponentBehaviourTypeId::from(&ty), factory).await
28        }
29    }
30
31    /// Unregisters a factory for creating relation component behaviours.
32    #[allow(unused_variables)]
33    async fn unregister(&self, component_behaviour_ty: &ComponentBehaviourTypeId);
34
35    /// Unregisters the behaviour factories for the given component behaviour types.
36    async fn unregister_all(&self, tys: &ComponentBehaviourTypeIds) {
37        let mut tys = tokio_stream::iter(tys.iter());
38        while let Some(ty) = tys.next().await {
39            self.unregister(&ty).await
40        }
41    }
42}