aboutsummaryrefslogtreecommitdiff
path: root/examples/03-controlled-inputs/README.md
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/03-controlled-inputs/README.md
parentef41bf37c5042aea3a79bdf4883d5a0946462469 (diff)
downloadlustre-9d0aa7738449ac70787dfced639b0573432ee005.tar.gz
lustre-9d0aa7738449ac70787dfced639b0573432ee005.zip
:memo: Update examples docs.
Diffstat (limited to 'examples/03-controlled-inputs/README.md')
-rw-r--r--examples/03-controlled-inputs/README.md21
1 files changed, 18 insertions, 3 deletions
diff --git a/examples/03-controlled-inputs/README.md b/examples/03-controlled-inputs/README.md
index 30fda75..95ca620 100644
--- a/examples/03-controlled-inputs/README.md
+++ b/examples/03-controlled-inputs/README.md
@@ -18,8 +18,9 @@ two things:
ui.input([
// Input's value is fixed to the model's `value` field
attribute.value(model.value),
- // Whenever the input changes, we send a `GotInput` message with the new value
- event.on_input(GotInput)
+ // Whenever the input changes, we send a `UserUpdatedMessage` message with the
+ // new value
+ event.on_input(UserUpdatedMessage)
])
```
@@ -36,7 +37,7 @@ value is less than 10 characters long.
```gleam
case msg {
- GotInput(value) -> {
+ UserUpdatedMessage(value) -> {
let length = string.length(value)
case length <= model.max {
@@ -48,6 +49,20 @@ case msg {
...
```
+## A note on message naming
+
+In our [state management guide](https://hexdocs.pm/lustre/guide/02-state-management.html)
+we touch on the idea of "messages not actions." We think the best way to name your
+messages is following a "Subject Verb Object" pattern: `UserUpdatedMessage` not
+`SetMessage` and so on.
+
+This approach to message naming can feel a cumbersome at first, especially for
+small examples like this. One of Lustre's super powers is that as your app grows
+in size, your `Msg` type becomes a very helpful overview of all the different
+events your app can handle. When they take the form of `Subject Verb Object` it
+gives you an immediate sense of the different things that speak to your app: how
+much is coming from your backend, how much is user input, and so on.
+
## Getting help
If you're having trouble with Lustre or not sure what the right way to do