aboutsummaryrefslogtreecommitdiff
path: root/test-apps/nested-element-map/src
diff options
context:
space:
mode:
authorBenjamin Rhodes <ben@nerdyworm.com>2024-04-26 14:04:24 -0700
committerGitHub <noreply@github.com>2024-04-26 22:04:24 +0100
commitb450997d71340a683d100e01182d695a0f49a03a (patch)
treebe579844845d62c68f721f0cbfd831fffedacdb4 /test-apps/nested-element-map/src
parentbc445f49a4748a96e3b84f14d70727729c5dfbb8 (diff)
downloadlustre-b450997d71340a683d100e01182d695a0f49a03a.tar.gz
lustre-b450997d71340a683d100e01182d695a0f49a03a.zip
🔀 Fix a bug where nested `Map` nodes were not morphed. (#115)
* ensure nested subtrees are morphed * Add a test-app for nested element map bug
Diffstat (limited to 'test-apps/nested-element-map/src')
-rw-r--r--test-apps/nested-element-map/src/app.gleam51
1 files changed, 51 insertions, 0 deletions
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),
+ ])
+}