aboutsummaryrefslogtreecommitdiff
path: root/examples/05-http-requests/src
diff options
context:
space:
mode:
authorHayleigh Thompson <me@hayleigh.dev>2024-03-27 20:57:14 +0000
committerHayleigh Thompson <me@hayleigh.dev>2024-03-27 20:57:14 +0000
commit9d0aa7738449ac70787dfced639b0573432ee005 (patch)
tree5f4ce51e99d6d87457982e3cdc8657fc19e784b2 /examples/05-http-requests/src
parentef41bf37c5042aea3a79bdf4883d5a0946462469 (diff)
downloadlustre-9d0aa7738449ac70787dfced639b0573432ee005.tar.gz
lustre-9d0aa7738449ac70787dfced639b0573432ee005.zip
:memo: Update examples docs.
Diffstat (limited to 'examples/05-http-requests/src')
-rw-r--r--examples/05-http-requests/src/app.gleam16
1 files changed, 9 insertions, 7 deletions
diff --git a/examples/05-http-requests/src/app.gleam b/examples/05-http-requests/src/app.gleam
index 04e0af6..9442cf3 100644
--- a/examples/05-http-requests/src/app.gleam
+++ b/examples/05-http-requests/src/app.gleam
@@ -45,15 +45,15 @@ fn init(_) -> #(Model, Effect(Msg)) {
// UPDATE ----------------------------------------------------------------------
pub opaque type Msg {
- Refresh
- GotQuote(Result(Quote, HttpError))
+ UserClickedRefresh
+ ApiUpdatedQuote(Result(Quote, HttpError))
}
fn update(model: Model, msg: Msg) -> #(Model, Effect(Msg)) {
case msg {
- Refresh -> #(model, get_quote())
- GotQuote(Ok(quote)) -> #(Model(quote: Some(quote)), effect.none())
- GotQuote(Error(_)) -> #(model, effect.none())
+ UserClickedRefresh -> #(model, get_quote())
+ ApiUpdatedQuote(Ok(quote)) -> #(Model(quote: Some(quote)), effect.none())
+ ApiUpdatedQuote(Error(_)) -> #(model, effect.none())
}
}
@@ -66,7 +66,7 @@ fn get_quote() -> Effect(Msg) {
dynamic.field("content", dynamic.string),
)
- lustre_http.get(url, lustre_http.expect_json(decoder, GotQuote))
+ lustre_http.get(url, lustre_http.expect_json(decoder, ApiUpdatedQuote))
}
// VIEW ------------------------------------------------------------------------
@@ -79,7 +79,9 @@ fn view(model: Model) -> Element(Msg) {
ui.aside(
[aside.min_width(70), attribute.style([#("width", "60ch")])],
view_quote(model.quote),
- ui.button([event.on_click(Refresh)], [element.text("New quote")]),
+ ui.button([event.on_click(UserClickedRefresh)], [
+ element.text("New quote"),
+ ]),
),
)
}