reactive_graph_plugin_api/behaviours/relations/
relation_component_behaviour_registry.rs1use 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 #[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 #[allow(unused_variables)]
33 async fn unregister(&self, component_behaviour_ty: &ComponentBehaviourTypeId);
34
35 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}