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/nested.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/nested.gleam')
-rw-r--r-- | test/nested.gleam | 57 |
1 files changed, 0 insertions, 57 deletions
diff --git a/test/nested.gleam b/test/nested.gleam deleted file mode 100644 index b32a5a3..0000000 --- a/test/nested.gleam +++ /dev/null @@ -1,57 +0,0 @@ -// IMPORTS --------------------------------------------------------------------- - -import counter -import gleam/list -import gleam/map.{Map} -import gleam/pair -import lustre -import lustre/element.{Element} -import lustre/html.{div} - -// 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") - - Nil -} - -// MODEL ----------------------------------------------------------------------- - -type Model = - Map(Int, counter.Model) - -fn init() -> Model { - use counters, id <- list.fold(list.range(1, 10), map.new()) - - map.insert(counters, id, counter.init()) -} - -// UPDATE ---------------------------------------------------------------------- - -type Msg = - #(Int, counter.Msg) - -fn update(model: Model, msg: Msg) -> Model { - let #(id, counter_msg) = msg - let assert Ok(counter) = map.get(model, id) - - map.insert(model, id, counter.update(counter, counter_msg)) -} - -// RENDER ---------------------------------------------------------------------- - -fn render(model: Model) -> Element(Msg) { - let counters = { - use rest, id, counter <- map.fold(model, []) - let el = element.map(counter.render(counter), pair.new(id, _)) - - [el, ..rest] - } - - div([], counters) -} |