diff options
author | Hayleigh Thompson <me@hayleigh.dev> | 2023-07-19 10:49:57 +0100 |
---|---|---|
committer | Hayleigh Thompson <me@hayleigh.dev> | 2023-07-19 10:49:57 +0100 |
commit | 0cbfb11f09d67cd98e8a60d0fa351f8396d3f774 (patch) | |
tree | 1a43f19683fe6214de75f9d96d2a40cbe90b95eb /test/counter.gleam | |
parent | 52d3b605d23ad463da850a7294593ebfb4800cb3 (diff) | |
download | lustre-0cbfb11f09d67cd98e8a60d0fa351f8396d3f774.tar.gz lustre-0cbfb11f09d67cd98e8a60d0fa351f8396d3f774.zip |
:truck: Move examples into a subdirectory so they're more obviously not tests.
Diffstat (limited to 'test/counter.gleam')
-rw-r--r-- | test/counter.gleam | 56 |
1 files changed, 0 insertions, 56 deletions
diff --git a/test/counter.gleam b/test/counter.gleam deleted file mode 100644 index 126aecc..0000000 --- a/test/counter.gleam +++ /dev/null @@ -1,56 +0,0 @@ -// IMPORTS --------------------------------------------------------------------- - -import gleam/int -import lustre -import lustre/element.{Element, t} -import lustre/html.{button, div, p} -import lustre/event - -// MAIN ------------------------------------------------------------------------ - -pub fn main() { - // A `simple` lustre application doesn't produce `Cmd`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, render) - let assert Ok(_) = lustre.start(app, "body") -} - -// 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 render(model: Model) -> Element(Msg) { - div( - [], - [ - button([event.on_click(Incr)], [t("+")]), - button([event.on_click(Decr)], [t("-")]), - button([event.on_click(Reset)], [t("Reset")]), - p([], [t(int.to_string(model))]), - ], - ) -} |