reactive_graph_reactive_service_api/property/property_string/
operator.rs

1use crate::TypedReactivePropertyImpl;
2use reactive_graph_reactive_model_api::ReactiveInstance;
3use serde_json::json;
4use std::ops::Add;
5use std::ops::AddAssign;
6
7impl<IdType, ReactiveInstanceType, S> AddAssign<S> for TypedReactivePropertyImpl<IdType, ReactiveInstanceType, String>
8where
9    IdType: Clone,
10    ReactiveInstanceType: ReactiveInstance<IdType>,
11    S: Into<String>,
12{
13    fn add_assign(&mut self, rhs: S) {
14        let rhs = rhs.into();
15        if let Some(v) = self.reactive_instance.as_string(&self.property_name).map(|lhs| lhs.add(&rhs)) {
16            self.reactive_instance.set(&self.property_name, json!(v));
17        }
18    }
19}
20
21impl<IdTypeSelf, ReactiveInstanceTypeSelf, IdTypeOther, ReactiveInstanceTypeOther>
22    AddAssign<&TypedReactivePropertyImpl<IdTypeOther, ReactiveInstanceTypeOther, String>>
23    for TypedReactivePropertyImpl<IdTypeSelf, ReactiveInstanceTypeSelf, String>
24where
25    IdTypeSelf: Clone,
26    ReactiveInstanceTypeSelf: ReactiveInstance<IdTypeSelf>,
27    IdTypeOther: Clone,
28    ReactiveInstanceTypeOther: ReactiveInstance<IdTypeOther>,
29{
30    fn add_assign(&mut self, rhs: &TypedReactivePropertyImpl<IdTypeOther, ReactiveInstanceTypeOther, String>) {
31        let Some(other) = rhs.reactive_instance.as_string(&rhs.property_name) else {
32            return;
33        };
34        if let Some(v) = self.reactive_instance.as_string(&self.property_name).map(|lhs| lhs.add(&other)) {
35            self.reactive_instance.set(&self.property_name, json!(v));
36        }
37    }
38}