reactive_graph_reactive_model_api/
instance.rs

1use std::fmt::Display;
2
3use serde_json::Value;
4
5use reactive_graph_graph::ComponentContainer;
6use reactive_graph_graph::NamespacedTypeGetter;
7use reactive_graph_graph::PropertyInstanceSetter;
8
9use crate::ReactivePropertyContainer;
10
11/// A reactive instance is a container for properties and components.
12/// Furthermore the reactive instance has a namespaced type.
13pub trait ReactiveInstance<ID>:
14    ReactivePropertyContainer + ComponentContainer + PropertyInstanceSetter + NamespacedTypeGetter + Display + Clone + Send + Sync
15{
16    /// Returns the id of the reactive instance.
17    fn id(&self) -> ID;
18}
19
20pub trait ReactiveInstanceGetter<T> {
21    /// Returns the reactive instance.
22    fn get_reactive_instance(&self) -> &T;
23}
24
25pub trait ReactiveInstanceContainer<ID: Clone, T: ReactiveInstance<ID>> {
26    /// Returns the reactive instance of the behaviour.
27    fn get_reactive_instance(&self) -> &T;
28
29    fn get(&self, property_name: &str) -> Option<Value> {
30        self.get_reactive_instance().get(property_name)
31    }
32
33    fn set(&self, property_name: &str, value: Value) {
34        self.get_reactive_instance().set(property_name, value);
35    }
36}