reactive_graph_reactive_service_api/property/
operator.rs1use crate::TypedReactivePropertyImpl;
2use reactive_graph_reactive_model_api::ReactiveInstance;
3use std::ops::BitOrAssign;
4use std::ops::ShlAssign;
5use std::ops::ShrAssign;
6
7impl<IdTypeSelf, ReactiveInstanceTypeSelf, TargetSelf, IdTypeOther, ReactiveInstanceTypeOther, TargetOther>
8 ShlAssign<&TypedReactivePropertyImpl<IdTypeOther, ReactiveInstanceTypeOther, TargetOther>>
9 for TypedReactivePropertyImpl<IdTypeSelf, ReactiveInstanceTypeSelf, TargetSelf>
10where
11 IdTypeSelf: Clone,
12 ReactiveInstanceTypeSelf: ReactiveInstance<IdTypeSelf> + 'static,
13 IdTypeOther: Clone,
14 ReactiveInstanceTypeOther: ReactiveInstance<IdTypeOther>,
15{
16 fn shl_assign(&mut self, rhs: &TypedReactivePropertyImpl<IdTypeOther, ReactiveInstanceTypeOther, TargetOther>) {
17 let self_reactive_instance = self.reactive_instance.clone();
18 let self_property_name = self.property_name.clone();
19 self.reactive_instance.remove_observer(&self.property_name, rhs.handle_id);
21 rhs.reactive_instance.observe_with_handle(
22 &rhs.property_name,
23 move |v| {
24 self_reactive_instance.set(&self_property_name, v.clone());
25 },
26 self.handle_id,
27 );
28 if let Some(v) = rhs.reactive_instance.get(&rhs.property_name) {
29 self.reactive_instance.set(&self.property_name, v);
30 }
31 }
32}
33
34impl<IdTypeSelf, ReactiveInstanceTypeSelf, TargetSelf, IdTypeOther, ReactiveInstanceTypeOther, TargetOther>
35 ShrAssign<&TypedReactivePropertyImpl<IdTypeOther, ReactiveInstanceTypeOther, TargetOther>>
36 for TypedReactivePropertyImpl<IdTypeSelf, ReactiveInstanceTypeSelf, TargetSelf>
37where
38 IdTypeSelf: Clone,
39 ReactiveInstanceTypeSelf: ReactiveInstance<IdTypeSelf>,
40 IdTypeOther: Clone,
41 ReactiveInstanceTypeOther: ReactiveInstance<IdTypeOther> + 'static,
42{
43 fn shr_assign(&mut self, rhs: &TypedReactivePropertyImpl<IdTypeOther, ReactiveInstanceTypeOther, TargetOther>) {
44 let rhs_reactive_instance = rhs.reactive_instance.clone();
45 let rhs_property_name = rhs.property_name.clone();
46 rhs.reactive_instance.remove_observer(&rhs.property_name, self.handle_id);
48 self.reactive_instance.observe_with_handle(
49 &self.property_name,
50 move |v| {
51 rhs_reactive_instance.set(&rhs_property_name, v.clone());
52 },
53 rhs.handle_id,
54 );
55 if let Some(v) = self.reactive_instance.get(&self.property_name) {
56 rhs.reactive_instance.set(&rhs.property_name, v);
57 }
58 }
59}
60
61impl<IdTypeSelf, ReactiveInstanceTypeSelf, TargetSelf, IdTypeOther, ReactiveInstanceTypeOther, TargetOther>
62 BitOrAssign<&TypedReactivePropertyImpl<IdTypeOther, ReactiveInstanceTypeOther, TargetOther>>
63 for TypedReactivePropertyImpl<IdTypeSelf, ReactiveInstanceTypeSelf, TargetSelf>
64where
65 IdTypeSelf: Clone,
66 ReactiveInstanceTypeSelf: ReactiveInstance<IdTypeSelf>,
67 IdTypeOther: Clone,
68 ReactiveInstanceTypeOther: ReactiveInstance<IdTypeOther>,
69{
70 fn bitor_assign(&mut self, rhs: &TypedReactivePropertyImpl<IdTypeOther, ReactiveInstanceTypeOther, TargetOther>) {
71 rhs.reactive_instance.remove_observer(&rhs.property_name, self.handle_id);
72 self.reactive_instance.remove_observer(&rhs.property_name, rhs.handle_id);
73 println!("remove streams in both directions {} <--> {}", self.handle_id, rhs.handle_id);
74 }
75}