reactive_graph_std_state/behaviour/component/state_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 reactive_graph_reactive_model_impl::ReactiveEntity;
10use serde_json::Value;
11
12use reactive_graph_std_state_model::NAMESPACE_STATE;
13
14use crate::behaviour::component::state_debugger::StateDebuggerFactory;
15
16pub type StateDebuggerFunction = fn(Value, ReactiveEntity);
17
18const FN_LOG_DEBUG: StateDebuggerFunction = |v, entity_instance| {
19    debug!("{} {}", entity_instance.id, v);
20};
21
22const FN_LOG_TRACE: StateDebuggerFunction = |v, entity_instance| {
23    trace!("{} {}", entity_instance.id, v);
24};
25
26const FACTORY_CREATOR: EntityBehaviourFactoryCreator<StateDebuggerFunction> = |ty, f| Arc::new(StateDebuggerFactory::new(ty.clone(), f));
27
28/// Defines behaviour types and their functions
29/// Global, lazy, thread-safe, readonly, iterable
30pub static STATE_DEBUGGER_BEHAVIOURS: EntityBehaviourFunctionsStorage<StateDebuggerFunction> = LazyLock::new(|| {
31    EntityBehaviourFunctions::<StateDebuggerFunction>::with_namespace(NAMESPACE_STATE, FACTORY_CREATOR)
32        .behaviour("state_debugger_debug", FN_LOG_DEBUG)
33        .behaviour("state_debugger_trace", FN_LOG_TRACE)
34        .get()
35});
36
37// behaviour_functions!(
38//     STATE_DEBUGGER_BEHAVIOURS,
39//     StateDebuggerFunction,
40//     NAMESPACE_STATE,
41//     ("state_debugger_debug", FN_LOG_DEBUG),
42//     ("state_debugger_trace", FN_LOG_TRACE)
43// );