summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector@hecrj.dev>2024-09-13 22:50:59 +0200
committerLibravatar GitHub <noreply@github.com>2024-09-13 22:50:59 +0200
commite0da42efed23a8d5a664acb12a2c699147f2408a (patch)
treef25a1fd14b04b59b0973895396ef2cccf5f4e8ab
parente9e8e83ccabfa8c42323c748158e29e8b82ab485 (diff)
parent2367f7863a27fcfc00efeb07cd20f8bc16a2f951 (diff)
downloadiced-e0da42efed23a8d5a664acb12a2c699147f2408a.tar.gz
iced-e0da42efed23a8d5a664acb12a2c699147f2408a.tar.bz2
iced-e0da42efed23a8d5a664acb12a2c699147f2408a.zip
Merge pull request #2556 from dtoniolo/docs
Document how the state of a `Component` can be managed
-rw-r--r--widget/src/lazy/component.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/widget/src/lazy/component.rs b/widget/src/lazy/component.rs
index 659bc476..2bdfa2c0 100644
--- a/widget/src/lazy/component.rs
+++ b/widget/src/lazy/component.rs
@@ -31,6 +31,19 @@ use std::rc::Rc;
///
/// Additionally, a [`Component`] is capable of producing a `Message` to notify
/// the parent application of any relevant interactions.
+///
+/// # State
+/// A component can store its state in one of two ways: either as data within the
+/// implementor of the trait, or in a type [`State`][Component::State] that is managed
+/// by the runtime and provided to the trait methods. These two approaches are not
+/// mutually exclusive and have opposite pros and cons.
+///
+/// For instance, if a piece of state is needed by multiple components that reside
+/// in different branches of the tree, then it's more convenient to let a common
+/// ancestor store it and pass it down.
+///
+/// On the other hand, if a piece of state is only needed by the component itself,
+/// you can store it as part of its internal [`State`][Component::State].
#[cfg(feature = "lazy")]
#[deprecated(
since = "0.13.0",