reactive_graph_reactive_service_api/property/
constructor.rs

1use std::marker::PhantomData;
2
3use uuid::Uuid;
4
5use crate::TypedReactivePropertyCreator;
6use crate::TypedReactivePropertyImpl;
7use reactive_graph_reactive_model_api::ReactiveInstance;
8
9pub trait TypedReactivePropertyConstructor<IdType, ReactiveInstanceType>: TypedReactivePropertyCreator<IdType, ReactiveInstanceType>
10where
11    IdType: Clone,
12    ReactiveInstanceType: ReactiveInstance<IdType>,
13{
14    type ID;
15
16    type InstanceType: ReactiveInstance<Self::ID>;
17    type Target;
18
19    fn new(reactive_instance: Self::InstanceType, property_name: &str) -> Self;
20}
21
22impl<IdType, ReactiveInstanceType, Target> TypedReactivePropertyConstructor<IdType, ReactiveInstanceType>
23    for TypedReactivePropertyImpl<IdType, ReactiveInstanceType, Target>
24where
25    IdType: Clone,
26    ReactiveInstanceType: ReactiveInstance<IdType> + Clone,
27    TypedReactivePropertyImpl<IdType, ReactiveInstanceType, Target>: TypedReactivePropertyCreator<IdType, ReactiveInstanceType>,
28{
29    type ID = IdType;
30    type InstanceType = ReactiveInstanceType;
31    type Target = Target;
32
33    fn new(reactive_instance: Self::InstanceType, property_name: &str) -> Self {
34        let property = Self {
35            handle_id: Uuid::new_v4().as_u128(),
36            reactive_instance: reactive_instance.clone(),
37            property_name: property_name.to_string(),
38            id_type: PhantomData,
39            target: PhantomData,
40        };
41        if !reactive_instance.has_property(property_name) {
42            property.create();
43        }
44        property
45    }
46}