From ca3123aaba78cdaf30b0a775ddd0932db22c567f Mon Sep 17 00:00:00 2001 From: Hayleigh Thompson Date: Wed, 21 Feb 2024 22:34:10 +0000 Subject: :memo: Add a slightly more detailed explainer on effects. --- docs/guide/01-quickstart.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'docs/guide') 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 -- cgit v1.2.3