egui_mobius_reactive/reactive/
mod.rs

1//! Reactive state management system for thread-safe, real-time UI updates.
2//!
3//! This module provides a reactive system that enables automatic UI updates when state changes,
4//! with built-in thread safety and change detection. It's particularly useful for:
5//! 
6//! - Managing state that needs to be shared between UI and background threads
7//! - Creating computed values that automatically update when their dependencies change
8//! - Ensuring thread-safe access to shared state
9//! - Building responsive UIs that react to state changes in real-time
10//!
11//! # Architecture
12//!
13//! The reactive system consists of three main components:
14//!
15//! 1. `Dynamic<T>` - A thread-safe container for values that can be monitored for changes
16//! 2. `Derived<T>` - Computed values that automatically update when their dependencies change
17//! 3. `SignalRegistry` - A registry that manages reactive values and their dependencies
18//!
19//! # Example
20//!
21//! ```rust
22//! use std::sync::Arc;
23//! use egui_mobius_reactive::{Dynamic, Derived, SignalRegistry};
24//!
25//! // Create a registry to manage reactive values
26//! let registry = SignalRegistry::new();
27//!
28//! // Create a value that can be monitored for changes
29//! let count = Dynamic::new(0);
30//!
31//! // Create a derived value that depends on count
32//! let count_for_compute = count.clone();
33//! 
34//! let doubled = Derived::new(&[Arc::new(count.clone())], move || {
35//!     let val = *count_for_compute.lock();
36//!     val * 2
37//! });
38//!
39//! // Register the values with the registry
40//! registry.register_named_signal("count", Arc::new(count.clone()));
41//! registry.register_named_signal("doubled", Arc::new(doubled.clone()));
42//!
43//! // Values automatically update when dependencies change
44//! assert_eq!(doubled.get(), 0);
45//! count.set(5);
46//! std::thread::sleep(std::time::Duration::from_millis(200));
47//! assert_eq!(doubled.get(), 10);
48//! ```
49//!
50//! # Thread Safety
51//!
52//! All values in the reactive system are protected by `Arc<Mutex<T>>` for safe concurrent access.
53//! The system spawns dedicated background threads to monitor for changes and update derived values.
54//!
55//! # Performance Considerations
56//!
57//! - Change detection uses a polling approach with a 100ms interval
58//! - Consider using `parking_lot::Mutex` instead of `std::sync::Mutex` for better performance
59//! - Derived values are only recomputed when their dependencies actually change
60pub mod prelude;
61pub mod registry;
62pub mod dynamic;
63pub mod derived;
64pub mod core; 
65#[cfg(feature = "widgets")]
66pub mod widgets;
67pub mod reactive_math;
68pub mod reactive_state;
69
70
71
72
73
74