aboutsummaryrefslogtreecommitdiff
path: root/examples/nested
diff options
context:
space:
mode:
authorHayleigh Thompson <me@hayleigh.dev>2024-01-27 02:24:50 +0000
committerHayleigh Thompson <me@hayleigh.dev>2024-01-27 02:24:50 +0000
commitc34d1a0e9003d483752720466def696c30f705c8 (patch)
treeb6e693c3b3d971a9d449daeb461b1a867177ad39 /examples/nested
parent235fcd2ae0229272ebb0927806d301c8b887c1ba (diff)
downloadlustre-c34d1a0e9003d483752720466def696c30f705c8.tar.gz
lustre-c34d1a0e9003d483752720466def696c30f705c8.zip
:construction: Start replacing old test examples with structured examples.
Diffstat (limited to 'examples/nested')
-rw-r--r--examples/nested/gleam.toml7
-rw-r--r--examples/nested/manifest.toml15
-rw-r--r--examples/nested/src/nested.gleam57
-rw-r--r--examples/nested/src/nested/counter.gleam53
4 files changed, 0 insertions, 132 deletions
diff --git a/examples/nested/gleam.toml b/examples/nested/gleam.toml
deleted file mode 100644
index dd00c99..0000000
--- a/examples/nested/gleam.toml
+++ /dev/null
@@ -1,7 +0,0 @@
-name = "nested"
-version = "1.0.0"
-target = "javascript"
-
-[dependencies]
-gleam_stdlib = "~> 0.34"
-lustre = { path = "../../" } \ No newline at end of file
diff --git a/examples/nested/manifest.toml b/examples/nested/manifest.toml
deleted file mode 100644
index 6593d5e..0000000
--- a/examples/nested/manifest.toml
+++ /dev/null
@@ -1,15 +0,0 @@
-# This file was generated by Gleam
-# You typically do not need to edit this file
-
-packages = [
- { name = "gleam_erlang", version = "0.24.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "26BDB52E61889F56A291CB34167315780EE4AA20961917314446542C90D1C1A0" },
- { name = "gleam_json", version = "0.7.0", build_tools = ["gleam"], requirements = ["thoas", "gleam_stdlib"], otp_app = "gleam_json", source = "hex", outer_checksum = "CB405BD93A8828BCD870463DE29375E7B2D252D9D124C109E5B618AAC00B86FC" },
- { name = "gleam_otp", version = "0.9.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "gleam_erlang"], otp_app = "gleam_otp", source = "hex", outer_checksum = "5FADBBEC5ECF3F8B6BE91101D432758503192AE2ADBAD5602158977341489F71" },
- { name = "gleam_stdlib", version = "0.34.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "1FB8454D2991E9B4C0C804544D8A9AD0F6184725E20D63C3155F0AEB4230B016" },
- { name = "lustre", version = "3.1.1", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_json", "gleam_otp", "gleam_stdlib"], source = "local", path = "../.." },
- { name = "thoas", version = "0.4.1", build_tools = ["rebar3"], requirements = [], otp_app = "thoas", source = "hex", outer_checksum = "4918D50026C073C4AB1388437132C77A6F6F7C8AC43C60C13758CC0ADCE2134E" },
-]
-
-[requirements]
-gleam_stdlib = { version = "~> 0.34" }
-lustre = { path = "../../" }
diff --git a/examples/nested/src/nested.gleam b/examples/nested/src/nested.gleam
deleted file mode 100644
index 2e1b9ec..0000000
--- a/examples/nested/src/nested.gleam
+++ /dev/null
@@ -1,57 +0,0 @@
-// IMPORTS ---------------------------------------------------------------------
-
-import nested/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)
-}
diff --git a/examples/nested/src/nested/counter.gleam b/examples/nested/src/nested/counter.gleam
deleted file mode 100644
index 37af39a..0000000
--- a/examples/nested/src/nested/counter.gleam
+++ /dev/null
@@ -1,53 +0,0 @@
-// IMPORTS ---------------------------------------------------------------------
-
-import gleam/int
-import lustre
-import lustre/element.{type Element, text}
-import lustre/element/html.{button, div, p}
-import lustre/event
-
-// 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)
-}
-
-// MODEL -----------------------------------------------------------------------
-
-pub type Model =
- Int
-
-pub fn init(_) -> Model {
- 0
-}
-
-// UPDATE ----------------------------------------------------------------------
-
-pub opaque type Msg {
- Incr
- Decr
- Reset
-}
-
-pub fn update(model: Model, msg: Msg) -> Model {
- case msg {
- Incr -> model + 1
- Decr -> model - 1
- Reset -> 0
- }
-}
-
-// VIEW ------------------------------------------------------------------------
-
-pub fn view(model: Model) -> Element(Msg) {
- div([], [
- button([event.on_click(Incr)], [text("+")]),
- button([event.on_click(Decr)], [text("-")]),
- button([event.on_click(Reset)], [text("Reset")]),
- p([], [text(int.to_string(model))]),
- ])
-}