reactive_graph_std_value/behaviour/component/value_debugger/
functions.rs

1use std::sync::Arc;
2use std::sync::LazyLock;
3
4use log::debug;
5use log::trace;
6use reactive_graph_behaviour_model_impl::entity::EntityBehaviourFactoryCreator;
7use reactive_graph_behaviour_model_impl::entity::EntityBehaviourFunctions;
8use reactive_graph_behaviour_model_impl::entity::EntityBehaviourFunctionsStorage;
9use serde_json::Value;
10
11use reactive_graph_std_value_model::NAMESPACE_VALUE;
12
13use crate::behaviour::component::value_debugger::ValueDebuggerFactory;
14
15pub type ValueDebuggerFunction = fn(Value);
16
17const FN_LOG_DEBUG: ValueDebuggerFunction = |v| {
18    debug!("{}", v);
19};
20
21const FN_LOG_TRACE: ValueDebuggerFunction = |v| {
22    trace!("{}", v);
23};
24
25/// Factory
26const FACTORY_CREATOR: EntityBehaviourFactoryCreator<ValueDebuggerFunction> = |ty, f| Arc::new(ValueDebuggerFactory::new(ty.clone(), f));
27
28/// Defines behaviour types and their functions
29/// Global, lazy, thread-safe, readonly, iterable
30pub static VALUE_DEBUGGER_BEHAVIOURS: EntityBehaviourFunctionsStorage<ValueDebuggerFunction> = LazyLock::new(|| {
31    EntityBehaviourFunctions::<ValueDebuggerFunction>::with_namespace(NAMESPACE_VALUE, FACTORY_CREATOR)
32        .behaviour("value_debugger_debug", FN_LOG_DEBUG)
33        .behaviour("value_debugger_trace", FN_LOG_TRACE)
34        .get()
35});
36
37// LazyLock<BehaviourFunctionsReadOnlyView<Uuid, ReactiveEntity, ValueDebuggerFunction>>
38// BehaviourFunctions::<Uuid, ReactiveEntity, ValueDebuggerFunction>
39
40// entity_behaviour_functions!(VALUE_DEBUGGER_BEHAVIOURS, ValueDebuggerFunction, || {
41//     BehaviourFunctions::with_namespace(NAMESPACE_VALUE, FACTORY_CREATOR)
42//         .behaviour("value_debugger_debug", FN_LOG_DEBUG)
43//         .behaviour("value_debugger_trace", FN_LOG_TRACE)
44//         .get()
45// });
46
47// behaviour_functions!(
48//     VALUE_DEBUGGER_BEHAVIOURS,
49//     ValueDebuggerFunction,
50//     NAMESPACE_VALUE,
51//     ("value_debugger_debug", FN_LOG_DEBUG),
52//     ("value_debugger_trace", FN_LOG_TRACE)
53// );