From 48b04d9dc06f3f6190c8aafcb85ca12737634234 Mon Sep 17 00:00:00 2001 From: Jacob Scearcy Date: Fri, 19 Apr 2024 19:46:34 +1000 Subject: =?UTF-8?q?=F0=9F=94=80=20Add=20support=20for=20element=20fragment?= =?UTF-8?q?s.=20(#99)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * #16 add fragment POC * WIP * 16 add fragment support to morph * add keys for fragments * ensure proper fragment order, refactor to handle fragment/element more similarly * fix comment typo, incorrect child typo, simplify key check * fix comment typo * add snapshot tests * flatten fragment using fold right, appending elements * doc update --------- Co-authored-by: Hayleigh Thompson --- test/apps/fragment.gleam | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 test/apps/fragment.gleam (limited to 'test/apps') diff --git a/test/apps/fragment.gleam b/test/apps/fragment.gleam new file mode 100644 index 0000000..d20400e --- /dev/null +++ b/test/apps/fragment.gleam @@ -0,0 +1,45 @@ +// Similar to count app, with fragments and edge cases + +// IMPORTS --------------------------------------------------------------------- + +import gleam/int +import lustre/element.{text} +import lustre/element/html.{button, p} +import lustre/event + +// MODEL ----------------------------------------------------------------------- + +pub type Model = + Int + +pub fn init(count) { + count +} + +// UPDATE ---------------------------------------------------------------------- + +pub type Msg { + Increment + Decrement +} + +pub fn update(model, msg) { + case msg { + Increment -> model + 1 + Decrement -> model - 1 + } +} + +// VIEW ------------------------------------------------------------------------ + +pub fn view(model) { + let count = int.to_string(model) + element.fragment([ + element.fragment([p([], [element.text("start fragment")])]), + element.fragment([p([], [element.text("middle fragment")])]), + element.fragment([p([], [element.text(count)])]), + button([event.on_click(Decrement)], [text("-")]), + button([event.on_click(Increment)], [text("+")]), + p([], [element.text("order check, last element")]), + ]) +} -- cgit v1.2.3