aboutsummaryrefslogtreecommitdiff
path: root/examples/06-custom-effects/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/06-custom-effects/src
parentef41bf37c5042aea3a79bdf4883d5a0946462469 (diff)
downloadlustre-9d0aa7738449ac70787dfced639b0573432ee005.tar.gz
lustre-9d0aa7738449ac70787dfced639b0573432ee005.zip
:memo: Update examples docs.
Diffstat (limited to 'examples/06-custom-effects/src')
-rw-r--r--examples/06-custom-effects/src/app.gleam24
1 files changed, 12 insertions, 12 deletions
diff --git a/examples/06-custom-effects/src/app.gleam b/examples/06-custom-effects/src/app.gleam
index 5399903..e04484a 100644
--- a/examples/06-custom-effects/src/app.gleam
+++ b/examples/06-custom-effects/src/app.gleam
@@ -28,34 +28,34 @@ type Model {
}
fn init(_) -> #(Model, Effect(Msg)) {
- #(Model(message: None), read_localstorage("message", GotMessage))
+ #(Model(message: None), read_localstorage("message"))
}
// UPDATE ----------------------------------------------------------------------
pub opaque type Msg {
- GotInput(String)
- GotMessage(Result(String, Nil))
+ UserUpdatedMessage(String)
+ CacheUpdatedMessage(Result(String, Nil))
}
fn update(model: Model, msg: Msg) -> #(Model, Effect(Msg)) {
case msg {
- GotInput(input) -> #(
+ UserUpdatedMessage(input) -> #(
Model(message: Some(input)),
write_localstorage("message", input),
)
- GotMessage(Ok(message)) -> #(Model(message: Some(message)), effect.none())
- GotMessage(Error(_)) -> #(model, effect.none())
+ CacheUpdatedMessage(Ok(message)) -> #(
+ Model(message: Some(message)),
+ effect.none(),
+ )
+ CacheUpdatedMessage(Error(_)) -> #(model, effect.none())
}
}
-fn read_localstorage(
- key: String,
- to_msg: fn(Result(String, Nil)) -> msg,
-) -> Effect(msg) {
+fn read_localstorage(key: String) -> Effect(Msg) {
effect.from(fn(dispatch) {
do_read_localstorage(key)
- |> to_msg
+ |> CacheUpdatedMessage
|> dispatch
})
}
@@ -85,7 +85,7 @@ fn view(model: Model) -> Element(Msg) {
ui.field(
[],
[],
- ui.input([attribute.value(message), event.on_input(GotInput)]),
+ ui.input([attribute.value(message), event.on_input(UserUpdatedMessage)]),
[element.text("Type a message and refresh the page")],
),
)