aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHayleigh Thompson <me@hayleigh.dev>2024-02-21 22:34:10 +0000
committerHayleigh Thompson <me@hayleigh.dev>2024-02-21 22:34:10 +0000
commitca3123aaba78cdaf30b0a775ddd0932db22c567f (patch)
tree64f720eed1c029b0a30b0291c46940fae515e2ef
parent9dc23b95959297e6b5c119b0a4777322726e69fa (diff)
downloadlustre-ca3123aaba78cdaf30b0a775ddd0932db22c567f.tar.gz
lustre-ca3123aaba78cdaf30b0a775ddd0932db22c567f.zip
:memo: Add a slightly more detailed explainer on effects.
-rw-r--r--docs/guide/01-quickstart.md7
1 files changed, 6 insertions, 1 deletions
diff --git a/docs/guide/01-quickstart.md b/docs/guide/01-quickstart.md
index 6e8b13d..b678175 100644
--- a/docs/guide/01-quickstart.md
+++ b/docs/guide/01-quickstart.md
@@ -295,7 +295,7 @@ pub fn update(model: Model, msg: Msg) -> #(Model, effect.Effect(Msg)) {
case msg {
Increment -> #(Model(..model, count: model.count + 1), get_cat())
Decrement -> #(Model(..model, count: model.count - 1), effect.none())
- GotCat(Ok(cat)) -> #(Model(..model, [cat, ..model.cats]), effect.none())
+ GotCat(Ok(cat)) -> #(Model(..model, cats: [cat, ..model.cats]), effect.none())
GotCat(Error(_)) -> #(model, effect.none())
}
}
@@ -308,6 +308,11 @@ fn get_cat() -> effect.Effect(Msg) {
}
```
+**Note**: The `get_cat` function returns an `Effect` that tells the runtime how
+to fetch a cat image. It's important to know that the `get_cat` function doesn't
+perform the request directly! This is why we need to add the `GotCat` message
+variant: the runtime needs to know what to do with the response when it arrives.
+
This model of managed effects can feel cumbersome at first, but it comes with some
benefits. Forcing side effects to produce a message means our message type naturally
describes all the ways the world can communicate with our application; as an app