From b450997d71340a683d100e01182d695a0f49a03a Mon Sep 17 00:00:00 2001 From: Benjamin Rhodes Date: Fri, 26 Apr 2024 14:04:24 -0700 Subject: =?UTF-8?q?=F0=9F=94=80=20Fix=20a=20bug=20where=20nested=20`Map`?= =?UTF-8?q?=20nodes=20were=20not=20morphed.=20(#115)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ensure nested subtrees are morphed * Add a test-app for nested element map bug --- test-apps/nested-element-map/src/app.gleam | 51 ++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 test-apps/nested-element-map/src/app.gleam (limited to 'test-apps/nested-element-map/src/app.gleam') diff --git a/test-apps/nested-element-map/src/app.gleam b/test-apps/nested-element-map/src/app.gleam new file mode 100644 index 0000000..ed91763 --- /dev/null +++ b/test-apps/nested-element-map/src/app.gleam @@ -0,0 +1,51 @@ +import lustre +import lustre/element.{type Element, element} +import lustre/element/html +import lustre/event + +// MAIN ------------------------------------------------------------------------ + +pub fn main() { + let app = lustre.simple(init, update, view) + let assert Ok(_) = lustre.start(app, "#app", Nil) +} + +// MODEL ----------------------------------------------------------------------- + +type Model = + String + +fn init(_flags) -> Model { + "div" +} + +// UPDATE ---------------------------------------------------------------------- +pub opaque type Baby { + Waaa +} + +pub opaque type Child { + BabyMsg(Baby) +} + +pub opaque type Msg { + ChildMsg(Child) +} + +fn update(model: Model, _msg: Msg) -> Model { + model +} + +// VIEW ------------------------------------------------------------------------ + +fn view(_model: Model) -> Element(Msg) { + html.div([], [ + html.text("parent"), + html.div([], [ + html.text("child"), + html.div([event.on_click(Waaa)], [html.text("baby")]) + |> element.map(BabyMsg), + ]) + |> element.map(ChildMsg), + ]) +} -- cgit v1.2.3