diff options
author | Hayleigh Thompson <me@hayleigh.dev> | 2023-12-22 01:37:39 +0000 |
---|---|---|
committer | Hayleigh Thompson <me@hayleigh.dev> | 2023-12-22 11:01:21 +0000 |
commit | ff3a5e7ce450f1007ae39a47f4e1b431da04a23d (patch) | |
tree | e355b8c8cbc5c662b8f700360672d43ae1dce519 /examples/nested.gleam | |
parent | ec7b40fc801e5f5af372f7b0b6524ee0bfcf8d3c (diff) | |
download | lustre-ff3a5e7ce450f1007ae39a47f4e1b431da04a23d.tar.gz lustre-ff3a5e7ce450f1007ae39a47f4e1b431da04a23d.zip |
:recycle: Refactor example apps to use lustre/try instead of vite.
Diffstat (limited to 'examples/nested.gleam')
-rw-r--r-- | examples/nested.gleam | 57 |
1 files changed, 0 insertions, 57 deletions
diff --git a/examples/nested.gleam b/examples/nested.gleam deleted file mode 100644 index 89e68f0..0000000 --- a/examples/nested.gleam +++ /dev/null @@ -1,57 +0,0 @@ -// IMPORTS --------------------------------------------------------------------- - -import examples/counter -import gleam/list -import gleam/map.{type Map} -import gleam/pair -import lustre -import lustre/element.{type Element} -import lustre/element/html.{div} - -// 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) - - 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(Nil)) -} - -// 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 view(model: Model) -> Element(Msg) { - let counters = { - use rest, id, counter <- map.fold(model, []) - let el = element.map(counter.view(counter), pair.new(id, _)) - - [el, ..rest] - } - - div([], counters) -} |