1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
//! # State, Signals, and Effects
//!
//! Repose uses a small reactive core instead of an explicit widget tree with
//! mutable fields. There are three main pieces:
//!
//! - `Signal<T>` - observable, reactive value.
//! - `remember*` - lifecycle‑aware storage bound to composition.
//! - `effect` / `scoped_effect` - side‑effects with cleanup.
//!
//! ## Signals
//!
//! `Signal<T>` is a cloneable handle to a piece of state:
//!
//! ```rust
//! use repose_core::*;
//!
//! let count = signal(0);
//! count.set(1);
//! count.update(|v| *v += 1);
//! assert_eq!(count.get(), 2);
//! ```
//!
//! Reads participate in a dependency graph: when you call `get()` inside an
//! observer or `produce_state`, future writes will automatically recompute that
//! observer.
//!
//! ## Remembered state
//!
//! UI state is typically held in `remember_*` slots rather than globals:
//!
//! ```ignore
//! use repose_core::*;
//!
//! fn CounterView() -> View {
//! let count = remember_state(|| 0); // Rc<RefCell<i32>>
//!
//! let on_click = {
//! let count = count.clone();
//! move || *count.borrow_mut() += 1
//! };
//!
//! repose_ui::Button(
//! format!("Count = {}", *count.borrow()),
//! on_click,
//! )
//! }
//! ```
//!
//! - `remember` and `remember_state` are order‑based: the Nth call in a
//! composition slot always refers to the Nth stored value.
//! - `remember_with_key` and `remember_state_with_key` are key‑based and more
//! stable across conditional branches.
//!
//! ## Derived state
//!
//! `produce_state` computes a `Signal<T>` from other signals and recomputes it
//! automatically when dependencies change:
//!
//! ```rust
//! use repose_core::*;
//!
//! let first = signal("Jane".to_string());
//! let last = signal("Doe".to_string());
//!
//! let full = produce_state("full_name", {
//! let first = first.clone();
//! let last = last.clone();
//! move || format!("{} {}", first.get(), last.get())
//! });
//!
//! assert_eq!(full.get(), "Jane Doe");
//! ```
//!
//! ## Effects and cleanup
//!
//! Use `effect` / `scoped_effect` for one‑off side‑effects with cleanups:
//!
//! ```ignore
//! use repose_core::*;
//!
//! fn Example() -> View {
//! scoped_effect(|| {
//! log::info!("Mounted Example");
//! on_unmount(|| log::info!("Unmounted Example"))
//! });
//!
//! // ...
//! repose_ui::Box(Modifier::new())
//! }
//! ```
//!
//! - `effect` runs once when the view is composed and returns a `Dispose`
//! guard that will be run when the scope is torn down.
//! - `scoped_effect` is wired to the current `Scope` and is cleaned up on
//! scope disposal (e.g. when a navigation entry is popped).
//!
//! For long‑running tasks (network, timers), prefer building small helpers on
//! top of `scoped_effect` so everything cleans up correctly when the UI that
//! owns it disappears.
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use ;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use ;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use View;
/// Memoized composition scope with input + signal tracking.
///
/// Wraps a composable block, caching its output as long as:
/// 1. The explicit inputs are unchanged (by `Hash` comparison).
/// 2. No signal read during body execution has been written since last run.
///
/// When the cache is hit, the body is NOT executed -> the previously-composed
/// View is returned instead, with proper ID and composer cursor advancement
/// to keep sibling scopes consistent.
///
/// # Usage
///
/// ```ignore
/// use repose_core::*;
///
/// fn MyView(s: &mut Scheduler, title: &str, count: i32) -> View {
/// scope!("my_view", s, [title, count], {
/// Column(Modifier::new()).child((
/// Text(title),
/// Text(format!("Count: {count}")),
/// ))
/// })
/// }
/// ```
///
/// # Signal auto-tracking
///
/// Any `Signal::get()` call inside the body automatically registers the scope
/// as a dependency. When that signal is written, the scope is marked dirty and
/// recomposed on the next frame. You don't need to put signal values in the
/// input list -> the reactive system handles dependencies implicitly.
///
/// ```ignore
/// let size = signal(100.0);
/// scope!("animated", s, [], {
/// let cur = size.get(); // auto-tracked; cache invalidated on write
/// Box(Modifier::new().size(cur, cur))
/// })
/// ```
///
/// # `f32`/`f64` in explicit inputs
///
/// Float types don't implement `Hash`. For float inputs, use `.to_bits()`:
///
/// ```ignore
/// scope!("s", s, [my_float.to_bits()], { ... })
/// ```
///
/// Or -> better -> read floats from a `Signal<f32>` inside the body (auto-tracked).
///
/// # Compatibility with `remember`
///
/// `remember` slots consumed inside the body are tracked and properly advanced
/// on cache hit, so sibling `remember` calls remain consistent.