reactive_graph_std_state/behaviour/component/state_debugger/
functions.rs1use 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
28pub 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