aboutsummaryrefslogtreecommitdiff
path: root/test/example/main.gleam
diff options
context:
space:
mode:
authorHayleigh Thompson <me@hayleigh.dev>2022-05-14 10:26:39 +0100
committerHayleigh Thompson <me@hayleigh.dev>2022-05-14 10:26:39 +0100
commit9f76cbc815a29425d4b297fc5a60ebfa1777b929 (patch)
treecdfc627cec56207b42249b6772335f03de4177fa /test/example/main.gleam
parentbeab31ed70c81259cf4940232d7200d144d87e34 (diff)
downloadlustre-9f76cbc815a29425d4b297fc5a60ebfa1777b929.tar.gz
lustre-9f76cbc815a29425d4b297fc5a60ebfa1777b929.zip
:sparkles: Create a simple counter example.
Diffstat (limited to 'test/example/main.gleam')
-rw-r--r--test/example/main.gleam35
1 files changed, 35 insertions, 0 deletions
diff --git a/test/example/main.gleam b/test/example/main.gleam
new file mode 100644
index 0000000..cd9a71e
--- /dev/null
+++ b/test/example/main.gleam
@@ -0,0 +1,35 @@
+import gleam/int
+import lustre
+import lustre/attribute.{ style }
+import lustre/element.{ button, div, p, text }
+import lustre/event.{ dispatch, on_click }
+
+pub fn main () {
+ let selector = "[data-lustre-container]"
+ let program = lustre.application(0, update, render)
+
+ lustre.start(program, selector)
+}
+
+type Action {
+ Incr
+ Decr
+}
+
+fn update (state, action) {
+ case action {
+ Incr ->
+ state + 1
+
+ Decr ->
+ state - 1
+ }
+}
+
+fn render (state) {
+ div([ style([ #("display", "flex") ]) ], [
+ button([ on_click(dispatch(Decr)) ], [ text("-") ]),
+ p([], [ int.to_string(state) |> text ]),
+ button([ on_click(dispatch(Incr)) ], [ text("+") ])
+ ])
+}