aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorKero van Gelder <keroami@users.noreply.github.com>2023-04-05 14:33:00 +0200
committerGitHub <noreply@github.com>2023-04-05 13:33:00 +0100
commita1b2f0344a59e24ae4d16f1689a02ba72ced2b53 (patch)
tree83843c6afd048b2c770a811696e1947bf915ffaa /test
parent2feb2a8e1a427cb7545785e2678e4523533c432e (diff)
downloadlustre-a1b2f0344a59e24ae4d16f1689a02ba72ced2b53.tar.gz
lustre-a1b2f0344a59e24ae4d16f1689a02ba72ced2b53.zip
🐛 Avoid a race condition when dispatch is used twice from outside (#8)
* Upgrade examples to lustre 2.0 * Upgrade to gleam 0.27.0 * Fix: avoid a race condition when dispatch is used twice from outside E.g. websocket open + websocket msg arriving Application returns a Cmd from update(model, msg) but the Effect handler is *not* ran be React 18 before the websocket msg-arriving is handled by the Reducer. Result: The Cmd returned by update(model, msg) is dropped silently. --------- Co-authored-by: Kero van Gelder <kero@chmeee.org>
Diffstat (limited to 'test')
-rw-r--r--test/example/application/counter.gleam10
-rw-r--r--test/example/main.gleam2
-rw-r--r--test/playground/monaco.gleam2
3 files changed, 7 insertions, 7 deletions
diff --git a/test/example/application/counter.gleam b/test/example/application/counter.gleam
index 40c93e3..62d8599 100644
--- a/test/example/application/counter.gleam
+++ b/test/example/application/counter.gleam
@@ -5,7 +5,7 @@ import lustre
import lustre/attribute.{ style }
import lustre/cmd.{ Cmd }
import lustre/element.{ button, div, p, text }
-import lustre/event.{ dispatch, on_click }
+import lustre/event.{ on_click }
// MAIN ------------------------------------------------------------------------
@@ -16,7 +16,7 @@ pub fn main () -> Nil {
// `lustre.start` can return an `Error` if no DOM element is found that matches
// the selector. This is a fatal error for our examples, so we panic if that
// happens.
- assert Ok(_) = lustre.start(program, selector)
+ let assert Ok(_) = lustre.start(program, selector)
Nil
}
@@ -77,10 +77,10 @@ fn tick () -> Cmd(Action) {
// RENDER ----------------------------------------------------------------------
-pub fn render (state) {
+pub fn render (state: State) {
div([ style([ #("display", "flex") ]) ], [
- button([ on_click(dispatch(Decr)) ], [ text("-") ]),
+ button([ on_click(Decr) ], [ text("-") ]),
p([], [ int.to_string(state.count) |> text ]),
- button([ on_click(dispatch(Incr)) ], [ text("+") ])
+ button([ on_click(Incr) ], [ text("+") ]),
])
}
diff --git a/test/example/main.gleam b/test/example/main.gleam
index 7d9c063..21c4067 100644
--- a/test/example/main.gleam
+++ b/test/example/main.gleam
@@ -15,7 +15,7 @@ pub fn main () -> Nil {
// `lustre.start` can return an `Error` if no DOM element is found that matches
// the selector. This is a fatal error for our examples, so we panic if that
// happens.
- assert Ok(dispatch) = lustre.start(program, selector)
+ let assert Ok(dispatch) = lustre.start(program, selector)
dispatch(Counter(counter.Incr))
dispatch(Counter(counter.Incr))
diff --git a/test/playground/monaco.gleam b/test/playground/monaco.gleam
index f0927ca..14958ac 100644
--- a/test/playground/monaco.gleam
+++ b/test/playground/monaco.gleam
@@ -8,7 +8,7 @@ pub external fn render (attributes: List(Attribute(action))) -> Element(action)
pub fn on_change (handler: fn (String, fn (action) -> Nil) -> Nil) -> Attribute(action) {
event.on("change", fn (e, dispatch) {
- assert Ok(code) = dynamic.string(e)
+ let assert Ok(code) = dynamic.string(e)
handler(code, dispatch)
})