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
//! # State
//!
//! [`rememberMutableStateOf`] creates state that survives recomposition.
//! Reading it inside a composable subscribes that composable to it, so a write
//! recomposes exactly the readers and nothing else.
//!
//! ```no_run
//! #![allow(non_snake_case)]
//! use cranpose::prelude::*;
//! # use cranpose::{
//! # __branch_group_scope_deferred, branch_location_key,
//! # cached_branch_location_key, cached_composable_definition_key,
//! # caller_location_key,
//! # composable_definition_key, composable_identity_key, debug_label_current_scope,
//! # location_key,
//! # with_current_composer, CallbackHolder, Composer, Key, ParamState, ReturnSlot,
//! # };
//!
//! #[composable]
//! fn Counter() {
//! let count = rememberMutableStateOf(|| 0i32);
//!
//! Button(
//! Modifier::empty().padding(10.0),
//! ButtonSpec::default(),
//! move || count.set(count.get() + 1),
//! move || {
//! Text(
//! format!("Count: {}", count.get()),
//! Modifier::empty(),
//! TextStyle::default(),
//! );
//! },
//! );
//! }
//!
//! fn main() {}
//! ```
//!
//! State handles are `Copy`. Move them into closures directly; cloning them is
//! never necessary.
//!
//! | Call | Use it for |
//! | --- | --- |
//! | [`remember`] | A value computed once and not observed for changes. |
//! | [`rememberKeyed`] | A value recomputed only when its key changes. |
//! | [`rememberMutableStateOf`] | Observable state. |
//! | [`rememberUpdatedState`] | A value a long-lived effect should see fresh without restarting. |
//! | [`rememberCoroutineScope`] | A scope for work started from an event handler. |
//! | [`mutableStateOf`] | State owned outside the composition. |
//!
//! Reading state inside `draw_behind` or the lazy `graphics_layer` closure
//! subscribes only that node's visual phase. Animation values read there redraw
//! without recomposing or relaying out the composable. Reads outside an observed
//! composition, layout, or draw phase subscribe nothing.
//!
//! [`remember`]: crate::prelude::remember
//! [`rememberKeyed`]: crate::prelude::rememberKeyed
//! [`rememberMutableStateOf`]: crate::prelude::rememberMutableStateOf
//! [`rememberUpdatedState`]: crate::prelude::rememberUpdatedState
//! [`rememberCoroutineScope`]: crate::prelude::rememberCoroutineScope
//! [`mutableStateOf`]: crate::prelude::mutableStateOf