diff options
author | Hayleigh Thompson <me@hayleigh.dev> | 2023-07-18 00:25:12 +0100 |
---|---|---|
committer | Hayleigh Thompson <me@hayleigh.dev> | 2023-07-18 00:25:12 +0100 |
commit | 7b007a072f39cd69ff4ba16c5f766aa26fab47c9 (patch) | |
tree | b910cf9d6aeff55758acbf8312f3f27a3eb44009 /test/nested.gleam | |
parent | 3125e15f26737eeb5818e35ac25604c82e1f4139 (diff) | |
download | lustre-7b007a072f39cd69ff4ba16c5f766aa26fab47c9.tar.gz lustre-7b007a072f39cd69ff4ba16c5f766aa26fab47c9.zip |
:recycle: Update examples for new html API.
Diffstat (limited to 'test/nested.gleam')
-rw-r--r-- | test/nested.gleam | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/test/nested.gleam b/test/nested.gleam index 8be6891..b32a5a3 100644 --- a/test/nested.gleam +++ b/test/nested.gleam @@ -3,8 +3,10 @@ import counter import gleam/list import gleam/map.{Map} +import gleam/pair import lustre -import lustre/element.{Element, div} +import lustre/element.{Element} +import lustre/html.{div} // MAIN ------------------------------------------------------------------------ @@ -13,7 +15,7 @@ pub fn main() { // 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(dispatch) = lustre.start(app, "body") + let assert Ok(_) = lustre.start(app, "body") Nil } @@ -44,13 +46,12 @@ fn update(model: Model, msg: Msg) -> Model { // RENDER ---------------------------------------------------------------------- fn render(model: Model) -> Element(Msg) { - div( - [], - { - use #(id, counter) <- list.map(map.to_list(model)) - let tagger = fn(msg) { #(id, msg) } - - element.map(counter.render(counter), tagger) - }, - ) + let counters = { + use rest, id, counter <- map.fold(model, []) + let el = element.map(counter.render(counter), pair.new(id, _)) + + [el, ..rest] + } + + div([], counters) } |