aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHayleigh Thompson <me@hayleigh.dev>2023-07-14 19:56:34 +0100
committerHayleigh Thompson <me@hayleigh.dev>2023-07-14 19:56:34 +0100
commit7d068ba4515763da9ce644b489192aa9ed32fc0a (patch)
tree55beb730322633bda82c68796a7cca27d867fbb9
parent19d6bcffb8eda0f2b6069d3505e2ec67a4d51455 (diff)
downloadlustre-7d068ba4515763da9ce644b489192aa9ed32fc0a.tar.gz
lustre-7d068ba4515763da9ce644b489192aa9ed32fc0a.zip
:recycle: Upgrade syntax for Gleam v0.30
-rw-r--r--src/lustre.gleam23
-rw-r--r--src/lustre/attribute.gleam10
-rw-r--r--src/lustre/element.gleam20
-rw-r--r--src/lustre/event.gleam9
4 files changed, 29 insertions, 33 deletions
diff --git a/src/lustre.gleam b/src/lustre.gleam
index 073d03b..1628a33 100644
--- a/src/lustre.gleam
+++ b/src/lustre.gleam
@@ -49,7 +49,7 @@ import lustre/element.{Element}
/// <small>Someone please PR the Gleam docs generator to fix the monospace font,
/// thanks! 💖</small>
///
-pub external type App(model, msg)
+pub type App(model, msg)
pub type Error {
ElementNotFound
@@ -202,12 +202,11 @@ pub fn simple(
/// external fn set_timeout (f: fn () -> a, delay: Int) -> Nil
/// = "" "window.setTimeout"
///```
-pub external fn application(
- init: fn() -> #(model, Cmd(msg)),
- update: Update(model, msg),
- render: Render(model, msg),
-) -> App(model, msg) =
- "./lustre.ffi.mjs" "setup"
+@external(javascript, "./lustre.ffi.mjs", "setup")
+pub fn application(init init: fn() -> #(model, Cmd(msg)), update update: Update(
+ model,
+ msg,
+ ), render render: Render(model, msg)) -> App(model, msg)
// EFFECTS ---------------------------------------------------------------------
@@ -243,8 +242,8 @@ pub fn start(
|> result.replace_error(ElementNotFound)
}
-external fn start_(
- app: App(model, msg),
- selector: String,
-) -> Result(fn(msg) -> Nil, Nil) =
- "./lustre.ffi.mjs" "start"
+@external(javascript, "./lustre.ffi.mjs", "start")
+fn start_(app app: App(model, msg), selector selector: String) -> Result(
+ fn(msg) -> Nil,
+ Nil,
+)
diff --git a/src/lustre/attribute.gleam b/src/lustre/attribute.gleam
index 771a546..2553321 100644
--- a/src/lustre/attribute.gleam
+++ b/src/lustre/attribute.gleam
@@ -10,7 +10,7 @@ import gleam/string
/// Attributes are attached to specific elements. They're either key/value pairs
/// or event handlers.
///
-pub external type Attribute(msg)
+pub type Attribute(msg)
// CONSTRUCTORS ----------------------------------------------------------------
@@ -22,8 +22,8 @@ pub external type Attribute(msg)
/// - `Some(a)` -> `a`
/// - `None` -> `undefined`
///
-pub external fn attribute(name: String, value: any) -> Attribute(msg) =
- "../lustre.ffi.mjs" "attr"
+@external(javascript, "../lustre.ffi.mjs", "attr")
+pub fn attribute(name name: String, value value: any) -> Attribute(msg)
// COMMON ATTRIBUTES -----------------------------------------------------------
@@ -32,8 +32,8 @@ pub fn style(properties: List(#(String, String))) -> Attribute(msg) {
attribute("style", styles(properties))
}
-external fn styles(properties: List(#(String, String))) -> Dynamic =
- "../lustre.ffi.mjs" "styles"
+@external(javascript, "../lustre.ffi.mjs", "styles")
+fn styles(properties properties: List(#(String, String))) -> Dynamic
///
pub fn class(name: String) -> Attribute(msg) {
diff --git a/src/lustre/element.gleam b/src/lustre/element.gleam
index 7a0cae7..ca73082 100644
--- a/src/lustre/element.gleam
+++ b/src/lustre/element.gleam
@@ -8,7 +8,7 @@ import lustre/attribute.{Attribute, attribute}
///
///
-pub external type Element(msg)
+pub type Element(msg)
// CONSTRUCTORS ----------------------------------------------------------------
@@ -16,12 +16,10 @@ pub external type Element(msg)
/// tag name, a list of attributes (including event handlers), and a list of
/// child elements.
///
-pub external fn node(
- tag: String,
- attrs: List(Attribute(msg)),
- children: List(Element(msg)),
-) -> Element(msg) =
- "../lustre.ffi.mjs" "node"
+@external(javascript, "../lustre.ffi.mjs", "node")
+pub fn node(tag tag: String, attrs attrs: List(Attribute(msg)), children children: List(
+ Element(msg),
+ )) -> Element(msg)
// pub external fn stateful(
// init: state,
@@ -76,8 +74,8 @@ pub external fn node(
///
/// Render a Gleam string as an HTML text node.
///
-pub external fn text(content: String) -> Element(msg) =
- "../lustre.ffi.mjs" "text"
+@external(javascript, "../lustre.ffi.mjs", "text")
+pub fn text(content content: String) -> Element(msg)
// MANIPULATIONS ---------------------------------------------------------------
@@ -177,8 +175,8 @@ pub external fn text(content: String) -> Element(msg) =
/// If this feels like a lt of work... sometimes it is! Take a look at the docs
/// for [`stateful`](#stateful) elements to see how all this can be encapsulated.
///
-pub external fn map(element: Element(a), f: fn(a) -> b) -> Element(b) =
- "../lustre.ffi.mjs" "map"
+@external(javascript, "../lustre.ffi.mjs", "map")
+pub fn map(element element: Element(a), f f: fn(a) -> b) -> Element(b)
// CONSTRUCTING NODES ----------------------------------------------------------
// This list and grouping of nodes has been taken from the MDN reference at:
diff --git a/src/lustre/event.gleam b/src/lustre/event.gleam
index 0853c16..eb3ccd1 100644
--- a/src/lustre/event.gleam
+++ b/src/lustre/event.gleam
@@ -81,11 +81,10 @@ type Decoded(a) =
/// }
/// ```
///
-pub external fn on(
- name: String,
- handler: fn(Dynamic) -> Option(msg),
-) -> Attribute(msg) =
- "../lustre.ffi.mjs" "on"
+@external(javascript, "../lustre.ffi.mjs", "on")
+pub fn on(name name: String, handler handler: fn(Dynamic) -> Option(msg)) -> Attribute(
+ msg,
+)
// MOUSE EVENTS ----------------------------------------------------------------