From c34d1a0e9003d483752720466def696c30f705c8 Mon Sep 17 00:00:00 2001 From: Hayleigh Thompson Date: Sat, 27 Jan 2024 02:24:50 +0000 Subject: :construction: Start replacing old test examples with structured examples. --- examples/counter/src/counter.gleam | 53 -------------------------------------- 1 file changed, 53 deletions(-) delete mode 100644 examples/counter/src/counter.gleam (limited to 'examples/counter/src') diff --git a/examples/counter/src/counter.gleam b/examples/counter/src/counter.gleam deleted file mode 100644 index 37af39a..0000000 --- a/examples/counter/src/counter.gleam +++ /dev/null @@ -1,53 +0,0 @@ -// IMPORTS --------------------------------------------------------------------- - -import gleam/int -import lustre -import lustre/element.{type Element, text} -import lustre/element/html.{button, div, p} -import lustre/event - -// MAIN ------------------------------------------------------------------------ - -pub fn main() { - // A `simple` lustre application doesn't produce `Effect`s. These are best to - // start with if you're just getting started with lustre or you know you don't - // need the runtime to manage any side effects. - let app = lustre.simple(init, update, view) - let assert Ok(_) = lustre.start(app, "[data-lustre-app]", Nil) -} - -// MODEL ----------------------------------------------------------------------- - -pub type Model = - Int - -pub fn init(_) -> Model { - 0 -} - -// UPDATE ---------------------------------------------------------------------- - -pub opaque type Msg { - Incr - Decr - Reset -} - -pub fn update(model: Model, msg: Msg) -> Model { - case msg { - Incr -> model + 1 - Decr -> model - 1 - Reset -> 0 - } -} - -// VIEW ------------------------------------------------------------------------ - -pub fn view(model: Model) -> Element(Msg) { - div([], [ - button([event.on_click(Incr)], [text("+")]), - button([event.on_click(Decr)], [text("-")]), - button([event.on_click(Reset)], [text("Reset")]), - p([], [text(int.to_string(model))]), - ]) -} -- cgit v1.2.3