aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gleam.toml15
-rw-r--r--manifest.toml23
-rw-r--r--src/lustre.gleam2
-rw-r--r--src/lustre/element.gleam11
-rw-r--r--src/lustre/internals/runtime.gleam28
5 files changed, 44 insertions, 35 deletions
diff --git a/gleam.toml b/gleam.toml
index ecb9c3b..a6a2289 100644
--- a/gleam.toml
+++ b/gleam.toml
@@ -11,25 +11,24 @@ links = [
gleam = ">= 0.33.0"
internal_modules = [
+ "lustre/cli/*",
"lustre/internals",
"lustre/internals/*",
- "lustre/try",
- "lustre/cli/*",
]
[dependencies]
+argv = "~> 1.0"
+filepath = "~> 0.1"
+gleam_community_ansi = "~> 1.4"
gleam_erlang = "~> 0.23"
gleam_json = "~> 0.7"
gleam_otp = "~> 0.8"
gleam_stdlib = "~> 0.34"
-gleam_community_ansi = "~> 1.4"
-glint = "~> 0.15.0-rc1"
-argv = "~> 1.0"
-simplifile = "~> 1.1"
-tom = "~> 0.3"
+glint = "~> 0.15.0"
justin = "~> 1.0"
shellout = "~> 1.5"
-filepath = "~> 0.1"
+simplifile = "~> 1.4"
+tom = "~> 0.3"
[dev-dependencies]
birdie = "~> 1.0"
diff --git a/manifest.toml b/manifest.toml
index 75b71f8..c7f9a1c 100644
--- a/manifest.toml
+++ b/manifest.toml
@@ -3,22 +3,21 @@
packages = [
{ name = "argv", version = "1.0.1", build_tools = ["gleam"], requirements = [], otp_app = "argv", source = "hex", outer_checksum = "A6E9009E50BBE863EB37D963E4315398D41A3D87D0075480FC244125808F964A" },
- { name = "birdie", version = "1.0.2", build_tools = ["gleam"], requirements = ["rank", "simplifile", "gleam_erlang", "gleam_stdlib", "gap", "gleeunit", "glam", "gleam_community_ansi", "justin", "argv", "filepath"], otp_app = "birdie", source = "hex", outer_checksum = "93EA5D784F79FF0ACB58E055BFF8D8733D604CC3510F3CA863719A8EFF63FD61" },
- { name = "filepath", version = "0.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "filepath", source = "hex", outer_checksum = "534E8161A0DE192A9A105EFEC34369E9FD5834BB58ED449B5ACAEE8704358588" },
- { name = "gap", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "gleam_community_ansi"], otp_app = "gap", source = "hex", outer_checksum = "2EE1B0A17E85CF73A0C1D29DA315A2699117A8F549C8E8D89FA8261BE41EDEB1" },
- { name = "glam", version = "1.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "glam", source = "hex", outer_checksum = "02E0311862B9669C3E8CE73FA5A95D8FA457C6ACB48D95FBE808ABFAE0A1CEB0" },
- { name = "gleam_community_ansi", version = "1.4.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "gleam_community_colour"], otp_app = "gleam_community_ansi", source = "hex", outer_checksum = "FE79E08BF97009729259B6357EC058315B6FBB916FAD1C2FF9355115FEB0D3A4" },
+ { name = "birdie", version = "1.0.4", build_tools = ["gleam"], requirements = ["argv", "filepath", "gap", "gleam_community_ansi", "gleam_erlang", "gleam_stdlib", "gleeunit", "justin", "rank", "simplifile"], otp_app = "birdie", source = "hex", outer_checksum = "0F7E16A3B12957B5B4A3B39152BD6D6175941AF40C1838F86C5A909DCFF7CF04" },
+ { name = "filepath", version = "0.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "filepath", source = "hex", outer_checksum = "FC1B1B29438A5BA6C990F8047A011430BEC0C5BA638BFAA62718C4EAEFE00435" },
+ { name = "gap", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_community_ansi", "gleam_stdlib"], otp_app = "gap", source = "hex", outer_checksum = "2EE1B0A17E85CF73A0C1D29DA315A2699117A8F549C8E8D89FA8261BE41EDEB1" },
+ { name = "gleam_community_ansi", version = "1.4.0", build_tools = ["gleam"], requirements = ["gleam_community_colour", "gleam_stdlib"], otp_app = "gleam_community_ansi", source = "hex", outer_checksum = "FE79E08BF97009729259B6357EC058315B6FBB916FAD1C2FF9355115FEB0D3A4" },
{ name = "gleam_community_colour", version = "1.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_community_colour", source = "hex", outer_checksum = "A49A5E3AE8B637A5ACBA80ECB9B1AFE89FD3D5351FF6410A42B84F666D40D7D5" },
{ 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_json", version = "0.7.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "thoas"], otp_app = "gleam_json", source = "hex", outer_checksum = "CB405BD93A8828BCD870463DE29375E7B2D252D9D124C109E5B618AAC00B86FC" },
{ name = "gleam_otp", version = "0.9.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_stdlib"], 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 = "gleeunit", version = "1.0.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "D364C87AFEB26BDB4FB8A5ABDE67D635DC9FA52D6AB68416044C35B096C6882D" },
- { name = "glint", version = "0.15.0-rc1", build_tools = ["gleam"], requirements = ["gleam_community_colour", "gleam_stdlib", "snag", "gleam_community_ansi"], otp_app = "glint", source = "hex", outer_checksum = "3EE3C064D8A8B8E1D6202BEE3B417F68CFE046FBBCD16936A159F993480AF642" },
+ { name = "glint", version = "0.15.0", build_tools = ["gleam"], requirements = ["gleam_community_ansi", "gleam_community_colour", "gleam_stdlib", "snag"], otp_app = "glint", source = "hex", outer_checksum = "D5324DBE11F57BF0B303D99EA086D66B8DC319EE59C1355C76EBB1544187C237" },
{ name = "justin", version = "1.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "justin", source = "hex", outer_checksum = "7FA0C6DB78640C6DC5FBFD59BF3456009F3F8B485BF6825E97E1EB44E9A1E2CD" },
{ name = "rank", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "rank", source = "hex", outer_checksum = "5660E361F0E49CBB714CC57CC4C89C63415D8986F05B2DA0C719D5642FAD91C9" },
- { name = "shellout", version = "1.5.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "shellout", source = "hex", outer_checksum = "7B5DE499DBB3DDC25051FC1BB3770DD5466938B6A2AFA91A6FB4A4D49F4CB0D4" },
- { name = "simplifile", version = "1.3.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "059AEB3632D1EBF4C943E8C231DBD8861A8BBF2984B78C1FE49159F28338A1FF" },
+ { name = "shellout", version = "1.6.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "shellout", source = "hex", outer_checksum = "E2FCD18957F0E9F67E1F497FC9FF57393392F8A9BAEAEA4779541DE7A68DD7E0" },
+ { name = "simplifile", version = "1.4.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "AAFCF154F69B237D269FF2764890F61ABC4A7EF2A592D44D67627B99694539D9" },
{ name = "snag", version = "0.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "snag", source = "hex", outer_checksum = "54D32E16E33655346AA3E66CBA7E191DE0A8793D2C05284E3EFB90AD2CE92BCC" },
{ name = "thoas", version = "0.4.1", build_tools = ["rebar3"], requirements = [], otp_app = "thoas", source = "hex", outer_checksum = "4918D50026C073C4AB1388437132C77A6F6F7C8AC43C60C13758CC0ADCE2134E" },
{ name = "tom", version = "0.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "tom", source = "hex", outer_checksum = "0831C73E45405A2153091226BF98FB485ED16376988602CC01A5FD086B82D577" },
@@ -27,15 +26,15 @@ packages = [
[requirements]
argv = { version = "~> 1.0" }
birdie = { version = "~> 1.0" }
-filepath = { version = "~> 0.1"}
+filepath = { version = "~> 0.1" }
gleam_community_ansi = { version = "~> 1.4" }
gleam_erlang = { version = "~> 0.23" }
gleam_json = { version = "~> 0.7" }
gleam_otp = { version = "~> 0.8" }
gleam_stdlib = { version = "~> 0.34" }
gleeunit = { version = "~> 1.0" }
-glint = { version = "~> 0.15.0-rc1" }
+glint = { version = "~> 0.15.0" }
justin = { version = "~> 1.0" }
shellout = { version = "~> 1.5" }
-simplifile = { version = "~> 1.1" }
+simplifile = { version = "~> 1.4" }
tom = { version = "~> 0.3" }
diff --git a/src/lustre.gleam b/src/lustre.gleam
index 7aeb6b4..95c8939 100644
--- a/src/lustre.gleam
+++ b/src/lustre.gleam
@@ -161,7 +161,7 @@
import argv
import gleam/bool
import gleam/dict.{type Dict}
-import gleam/dynamic.{type Decoder, type Dynamic}
+import gleam/dynamic.{type Decoder}
import gleam/erlang/process.{type Subject}
import gleam/otp/actor.{type StartError}
import gleam/result
diff --git a/src/lustre/element.gleam b/src/lustre/element.gleam
index 930dead..1c1fa68 100644
--- a/src/lustre/element.gleam
+++ b/src/lustre/element.gleam
@@ -17,6 +17,11 @@ import lustre/internals/patch
pub type Element(msg) =
vdom.Element(msg)
+/// Patches are sent by server components to any connected renderers. Because
+/// server components are not opinionated about your network layer or how your
+/// wider application is organised, it is your responsibility to make sure a `Patch`
+/// makes its way to the server component client runtime.
+///
pub type Patch(msg) =
patch.Patch(msg)
@@ -135,6 +140,12 @@ fn escape(escaped: String, content: String) -> String {
// MANIPULATIONS ---------------------------------------------------------------
+/// The `Element` type is parameterised by the type of messages it can produce
+/// from events. Sometimes you might end up with a fragment of HTML from another
+/// library or module that produces a different type of message: this function lets
+/// you map the messages produced from one type to another.
+///
+/// Think of it like `list.map` or `result.map` but for HTML events!
///
pub fn map(element: Element(a), f: fn(a) -> b) -> Element(b) {
case element {
diff --git a/src/lustre/internals/runtime.gleam b/src/lustre/internals/runtime.gleam
index 646baf4..a907656 100644
--- a/src/lustre/internals/runtime.gleam
+++ b/src/lustre/internals/runtime.gleam
@@ -18,9 +18,9 @@ import lustre/internals/vdom
///
///
-type State(runtime, model, msg) {
+type State(model, msg, runtime) {
State(
- self: Subject(Action(runtime, msg)),
+ self: Subject(Action(msg, runtime)),
model: model,
update: fn(model, msg) -> #(model, Effect(msg)),
view: fn(model) -> Element(msg),
@@ -33,7 +33,7 @@ type State(runtime, model, msg) {
///
///
-pub type Action(runtime, msg) {
+pub type Action(msg, runtime) {
AddRenderer(Dynamic, fn(Patch(msg)) -> Nil)
Attrs(List(#(String, Dynamic)))
Batch(List(msg), Effect(msg))
@@ -42,7 +42,7 @@ pub type Action(runtime, msg) {
Emit(String, Json)
Event(String, Dynamic)
RemoveRenderer(Dynamic)
- SetSelector(Selector(Action(runtime, msg)))
+ SetSelector(Selector(Action(msg, runtime)))
Shutdown
}
@@ -61,7 +61,7 @@ pub fn start(
update: fn(model, msg) -> #(model, Effect(msg)),
view: fn(model) -> Element(msg),
on_attribute_change: Dict(String, Decoder(msg)),
-) -> Result(Subject(Action(runtime, msg)), StartError) {
+) -> Result(Subject(Action(msg, runtime)), StartError) {
let timeout = 1000
let init = fn() {
let self = process.new_subject()
@@ -89,9 +89,9 @@ pub fn start(
@target(erlang)
fn loop(
- message: Action(runtime, msg),
- state: State(runtime, model, msg),
-) -> Next(Action(runtime, msg), State(runtime, model, msg)) {
+ message: Action(msg, runtime),
+ state: State(model, msg, runtime),
+) -> Next(Action(msg, runtime), State(model, msg, runtime)) {
case message {
Attrs(attrs) -> {
list.filter_map(attrs, fn(attr) {
@@ -213,7 +213,7 @@ fn run_renderers(
}
@target(erlang)
-fn run_effects(effects: Effect(msg), self: Subject(Action(runtime, msg))) -> Nil {
+fn run_effects(effects: Effect(msg), self: Subject(Action(msg, runtime))) -> Nil {
let dispatch = fn(msg) { actor.send(self, Dispatch(msg)) }
let emit = fn(name, event) { actor.send(self, Emit(name, event)) }
@@ -234,15 +234,15 @@ pub fn start(
update: fn(model, msg) -> #(model, Effect(msg)),
view: fn(model) -> Element(msg),
on_attribute_change: Dict(String, Decoder(msg)),
-) -> Result(Subject(Action(runtime, msg)), StartError) {
+) -> Result(Subject(Action(msg, runtime)), StartError) {
panic
}
@target(javascript)
fn loop(
- message: Action(runtime, msg),
- state: State(runtime, model, msg),
-) -> Next(Action(runtime, msg), State(runtime, model, msg)) {
+ message: Action(msg, runtime),
+ state: State(model, msg, runtime),
+) -> Next(Action(msg, runtime), State(model, msg, runtime)) {
panic
}
@@ -255,6 +255,6 @@ fn run_renderers(
}
@target(javascript)
-fn run_effects(effects: Effect(msg), self: Subject(Action(runtime, msg))) -> Nil {
+fn run_effects(effects: Effect(msg), self: Subject(Action(msg, runtime))) -> Nil {
panic
}