diff options
Diffstat (limited to 'examples/04-custom-event-handlers')
-rw-r--r-- | examples/04-custom-event-handlers/README.md | 4 | ||||
-rw-r--r-- | examples/04-custom-event-handlers/src/app.gleam | 12 |
2 files changed, 6 insertions, 10 deletions
diff --git a/examples/04-custom-event-handlers/README.md b/examples/04-custom-event-handlers/README.md index a2a09c5..434725a 100644 --- a/examples/04-custom-event-handlers/README.md +++ b/examples/04-custom-event-handlers/README.md @@ -74,7 +74,3 @@ In this [example code](./src/app.gleam#L63), we define a custom input handler ca If you're having trouble with Lustre or not sure what the right way to do something is, the best place to get help is the [Gleam Discord server](https://discord.gg/Fm8Pwmy). You could also open an issue on the [Lustre GitHub repository](https://github.com/lustre-labs/lustre/issues). - -While our docs are still a work in progress, the official [Elm guide](https://guide.elm-lang.org) -is also a great resource for learning about the Model-View-Update architecture -and the kinds of patterns that Lustre is built around. diff --git a/examples/04-custom-event-handlers/src/app.gleam b/examples/04-custom-event-handlers/src/app.gleam index c3f5d0b..011b09c 100644 --- a/examples/04-custom-event-handlers/src/app.gleam +++ b/examples/04-custom-event-handlers/src/app.gleam @@ -37,20 +37,20 @@ fn init(_) -> Model { // UPDATE ---------------------------------------------------------------------- pub opaque type Msg { - GotInput(value: String) - Reset + UserUpdatedMessage(value: String) + UserResetMessage } fn update(model: Model, msg: Msg) -> Model { case msg { - GotInput(value) -> { + UserUpdatedMessage(value) -> { let length = string.length(value) case length <= model.max { True -> Model(..model, value: value, length: length) False -> model } } - Reset -> Model(..model, value: "", length: 0) + UserResetMessage -> Model(..model, value: "", length: 0) } } @@ -66,7 +66,7 @@ fn view(model: Model) -> Element(Msg) { let loud = string.uppercase(value) - Ok(GotInput(loud)) + Ok(UserUpdatedMessage(loud)) } ui.centre( @@ -79,7 +79,7 @@ fn view(model: Model) -> Element(Msg) { ui.input([attribute.value(model.value), event.on("input", make_it_loud)]), [element.text(length <> "/" <> max)], ), - ui.button([event.on_click(Reset)], [element.text("Reset")]), + ui.button([event.on_click(UserResetMessage)], [element.text("Reset")]), ), ) } |