pub struct ReactiveList { /* private fields */ }Expand description
A reactive list: for item in $items key id (or, keyless, for item in $items) in .rsx. Re-runs its
source reactively and reconciles the item widgets — reused keys/positions keep their node/widget, new
ones are built, gone ones are disposed, and the layout children are reordered — instead of rebuilding the
whole block on every change. new/with_gap reconcile by key (identity-stable); positional/
positional_with_gap reconcile by index (no key clause needed, cheap append/truncate).
Implementations§
Source§impl ReactiveList
impl ReactiveList
Sourcepub fn as_row(self) -> Self
pub fn as_row(self) -> Self
Runs the reconciled items along the horizontal axis instead of stacking them.
Every constructor builds a column, because a list’s own node exists before it is attached and
cannot ask a parent it does not have yet. A for written inside a row reconciles into that row
as a transparent fragment and never reaches here; one that cannot — inside a reactive if, say,
which owns a node of its own — is boxed, and this is how it learns which way its items run.
Sourcepub fn new<Item, Key, S, K, B>(
source: S,
key: K,
build: B,
gap: f32,
) -> Result<Self, LayoutError>where
Key: Hash + 'static,
Item: 'static,
S: Fn() -> Vec<Item> + 'static,
K: Fn(&Item) -> Key + 'static,
B: Fn(Item) -> Result<Box<dyn LayoutItem>, LayoutError> + 'static,
pub fn new<Item, Key, S, K, B>(
source: S,
key: K,
build: B,
gap: f32,
) -> Result<Self, LayoutError>where
Key: Hash + 'static,
Item: 'static,
S: Fn() -> Vec<Item> + 'static,
K: Fn(&Item) -> Key + 'static,
B: Fn(Item) -> Result<Box<dyn LayoutItem>, LayoutError> + 'static,
source reads the reactive item collection; key extracts a stable identity per item; build
constructs one widget per item, creating its nodes against the live (thread-local) layout tree
from inside the reconcile effect.
Sourcepub fn with_style<Item, Key, S, K, B>(
container_style: LayoutStyle,
source: S,
key: K,
build: B,
) -> Result<Self, LayoutError>where
Key: Hash + 'static,
Item: 'static,
S: Fn() -> Vec<Item> + 'static,
K: Fn(&Item) -> Key + 'static,
B: Fn(Item) -> Result<Box<dyn LayoutItem>, LayoutError> + 'static,
pub fn with_style<Item, Key, S, K, B>(
container_style: LayoutStyle,
source: S,
key: K,
build: B,
) -> Result<Self, LayoutError>where
Key: Hash + 'static,
Item: 'static,
S: Fn() -> Vec<Item> + 'static,
K: Fn(&Item) -> Key + 'static,
B: Fn(Item) -> Result<Box<dyn LayoutItem>, LayoutError> + 'static,
Keyed like new/with_gap, but the caller supplies the container’s
LayoutStyle — flex direction, gap, alignment. Use it for a horizontal reactive row (e.g. a bar’s
workspace chips), which the column-oriented constructors can’t express.
Sourcepub fn positional<Item, S, B>(
source: S,
build: B,
gap: f32,
) -> Result<Self, LayoutError>where
Item: 'static,
S: Fn() -> Vec<Item> + 'static,
B: Fn(Item) -> Result<Box<dyn LayoutItem>, LayoutError> + 'static,
pub fn positional<Item, S, B>(
source: S,
build: B,
gap: f32,
) -> Result<Self, LayoutError>where
Item: 'static,
S: Fn() -> Vec<Item> + 'static,
B: Fn(Item) -> Result<Box<dyn LayoutItem>, LayoutError> + 'static,
A keyless reactive list: for item in $items with no key clause. Reconciles by POSITION — the
item at index i always reuses the node previously at index i, so an append/truncate reuses every
surviving node cheaply, but a reorder rebuilds rather than moving nodes (no per-item identity without
a key).
Sourcepub fn keyed<Item, Key, S, K, B>(
source: S,
key: K,
build: B,
) -> Result<Self, LayoutError>where
Key: Hash + 'static,
Item: Clone + 'static,
S: Fn() -> Vec<Item> + 'static,
K: Fn(&Item) -> Key + 'static,
B: Fn(ReadSignal<Item>) -> Result<Box<dyn LayoutItem>, LayoutError> + 'static,
pub fn keyed<Item, Key, S, K, B>(
source: S,
key: K,
build: B,
) -> Result<Self, LayoutError>where
Key: Hash + 'static,
Item: Clone + 'static,
S: Fn() -> Vec<Item> + 'static,
K: Fn(&Item) -> Key + 'static,
B: Fn(ReadSignal<Item>) -> Result<Box<dyn LayoutItem>, LayoutError> + 'static,
A keyed list whose builder receives a live handle to its item rather than a copy of it.
The difference decides what a row is allowed to be. With an owned snapshot, a key that persists reuses the widget and the new value is discarded — so a row that must follow its data has to be keyed on that data, which rebuilds it and throws away whatever local state it held: a caret, a drag in progress, a scroll position. Keying on identity and reading the value through a handle separates the two questions — the key decides whether this is still the same row, the handle carries what that row now says.
Use Self::new where a row genuinely is its value, which most lists are, and this where a row
outlives its contents.