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::{
18//! prelude::*,
19//! radio::*,
20//! };
21//!
22//! #[derive(Default, Clone)]
23//! struct AppState {
24//! count: i32,
25//! }
26//!
27//! #[derive(PartialEq, Eq, Clone, Debug, Copy, Hash)]
28//! enum AppChannel {
29//! Count,
30//! }
31//!
32//! impl RadioChannel<AppState> for AppChannel {}
33//!
34//! fn app() -> impl IntoElement {
35//! // Initialize the radio station
36//! use_init_radio_station::<AppState, AppChannel>(AppState::default);
37//!
38//! rect().child(Counter {})
39//! }
40//!
41//! #[derive(PartialEq)]
42//! struct Counter {}
43//!
44//! impl Component for Counter {
45//! fn render(&self) -> impl IntoElement {
46//! // Subscribe to the Count channel
47//! let mut radio = use_radio(AppChannel::Count);
48//!
49//! rect()
50//! .child(format!("Count: {}", radio.read().count))
51//! .child(
52//! Button::new()
53//! .on_press(move |_| radio.write().count += 1)
54//! .child("+"),
55//! )
56//! }
57//! }
58//! ```
59//!
60//! ## Advanced Features
61//!
62//! - **Multiple Channels**: Subscribe to different channels for different types of updates.
63//! - **Derived Channels**: Notify multiple channels from a single write operation.
64//! - **Reducers**: Implement action-based state updates.
65//! - **Multi-window**: Share state across multiple windows using global radio stations.
66//!
67//! See the examples in the repository for more advanced usage patterns.
68
69pub mod hooks;
70pub mod slice;
71
72pub mod prelude {
73 pub use freya_core::lifecycle::{
74 readable::{
75 IntoReadable,
76 Readable,
77 },
78 writable::{
79 IntoWritable,
80 Writable,
81 },
82 };
83
84 pub use crate::{
85 hooks::*,
86 slice::{
87 RadioSlice,
88 RadioSliceMut,
89 },
90 };
91}
92
93mod readable;
94mod writable;