diff options
Diffstat (limited to 'test/apps/counter.gleam')
-rw-r--r-- | test/apps/counter.gleam | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/test/apps/counter.gleam b/test/apps/counter.gleam new file mode 100644 index 0000000..b58b2ee --- /dev/null +++ b/test/apps/counter.gleam @@ -0,0 +1,41 @@ +// IMPORTS --------------------------------------------------------------------- + +import gleam/int +import lustre/element.{text} +import lustre/element/html.{button, div, p} +import lustre/event + +// MODEL ----------------------------------------------------------------------- + +pub type Model = + Int + +pub fn init(count) { + count +} + +// UPDATE ---------------------------------------------------------------------- + +pub type Msg { + Increment + Decrement +} + +pub fn update(model, msg) { + case msg { + Increment -> model + 1 + Decrement -> model - 1 + } +} + +// VIEW ------------------------------------------------------------------------ + +pub fn view(model) { + let count = int.to_string(model) + + div([], [ + p([], [text(count)]), + button([event.on_click(Decrement)], [text("-")]), + button([event.on_click(Increment)], [text("+")]), + ]) +} |