freya_radio/
lib.rs

1//! # Freya Radio 🧬
2//!
3//! Fully-typed global state management with a topics subscription system for Freya.
4//!
5//! Freya Radio provides a powerful way to manage global state in Freya applications
6//! with fine-grained control over which components re-render when the state changes.
7//!
8//! ## Key Concepts
9//!
10//! - **RadioStation**: The central hub that holds the global state and manages subscriptions.
11//! - **RadioChannel**: Defines channels for subscribing to specific types of state changes.
12//! - **Radio**: A reactive handle to the state for a specific channel.
13//!
14//! ## Basic Usage
15//!
16//! ```rust,no_run
17//! use freya::prelude::*;
18//! use freya_radio::prelude::*;
19//!
20//! #[derive(Default, Clone)]
21//! struct AppState {
22//!     count: i32,
23//! }
24//!
25//! #[derive(PartialEq, Eq, Clone, Debug, Copy, Hash)]
26//! enum AppChannel {
27//!     Count,
28//! }
29//!
30//! impl RadioChannel<AppState> for AppChannel {}
31//!
32//! fn app() -> impl IntoElement {
33//!     // Initialize the radio station
34//!     use_init_radio_station::<AppState, AppChannel>(AppState::default);
35//!
36//!     rect().child(Counter {})
37//! }
38//!
39//! #[derive(PartialEq)]
40//! struct Counter {}
41//!
42//! impl Component for Counter {
43//!     fn render(&self) -> impl IntoElement {
44//!         // Subscribe to the Count channel
45//!         let mut radio = use_radio(AppChannel::Count);
46//!
47//!         rect()
48//!             .child(format!("Count: {}", radio.read().count))
49//!             .child(
50//!                 Button::new()
51//!                     .on_press(move |_| radio.write().count += 1)
52//!                     .child("+"),
53//!             )
54//!     }
55//! }
56//! ```
57//!
58//! ## Advanced Features
59//!
60//! - **Multiple Channels**: Subscribe to different channels for different types of updates.
61//! - **Derived Channels**: Notify multiple channels from a single write operation.
62//! - **Reducers**: Implement action-based state updates.
63//! - **Multi-window**: Share state across multiple windows using global radio stations.
64//!
65//! See the examples in the repository for more advanced usage patterns.
66
67pub mod hooks;
68
69pub mod prelude {
70    pub use crate::hooks::*;
71}