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
use *;
/// Tracks the previously observed value of some external
/// reactive source.
///
/// Typical use: in a render closure, call
/// `previous.record(current)` at the top, then read
/// `previous.get_previous().get()` to find out what the
/// value was on the previous render. The two reads are
/// decoupled so callers can record and read independently.
///
/// # Why a `Signal<Option<T>>`?
///
/// Because the very first call to `record` has no
/// "previous" to report. The signal starts at `None`
/// and flips to `Some(value)` after the first record.
/// Render code can branch on the `Option` for
/// "first render vs subsequent".
///
/// # Lombok caveat
///
/// `Previous` cannot use Lombok `New` because the
/// `previous: Signal<Option<T>>` field would require
/// `T: Default` to satisfy `Signal::default()`. The
/// struct intentionally keeps `T: Clone + PartialEq +
/// 'static` (no `Default`), and the constructor is
/// hand-written in `impl.rs` to wrap the field with
/// `Signal::create(None)`.
/// `Previous<T>` is `Copy` when `T` is — `Signal<Option<T>>` is
/// already `Copy` (the signal registry hands out cheap `usize`
/// addresses), so this blanket impl is sound.