aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHayleigh Thompson <me@hayleigh.dev>2024-01-27 17:27:03 +0000
committerHayleigh Thompson <me@hayleigh.dev>2024-01-27 17:27:03 +0000
commitdcad7a49d0fa9d17f5e8c8e7677548be2967f364 (patch)
tree11589f10c2421f90cc4c36c41507a46b63d83dab
parentafb57d6dbdeb1628d420411a41fdbbd479b6732f (diff)
downloadlustre-dcad7a49d0fa9d17f5e8c8e7677548be2967f364.tar.gz
lustre-dcad7a49d0fa9d17f5e8c8e7677548be2967f364.zip
:truck: Move runtime module into internals/.
-rw-r--r--gleam.toml1
-rwxr-xr-xpriv/bin/esbuildbin0 -> 9756978 bytes
-rw-r--r--src/lustre.gleam2
-rw-r--r--src/lustre/internals/runtime.gleam (renamed from src/lustre/runtime.gleam)0
-rw-r--r--src/lustre/server.gleam36
-rw-r--r--test/lustre_test.gleam2
6 files changed, 20 insertions, 21 deletions
diff --git a/gleam.toml b/gleam.toml
index b12e429..a7082ed 100644
--- a/gleam.toml
+++ b/gleam.toml
@@ -13,7 +13,6 @@ gleam = ">= 0.33.0"
internal_modules = [
"lustre/internals",
"lustre/internals/*",
- "lustre/runtime",
"lustre/try",
]
diff --git a/priv/bin/esbuild b/priv/bin/esbuild
new file mode 100755
index 0000000..8c5cb93
--- /dev/null
+++ b/priv/bin/esbuild
Binary files differ
diff --git a/src/lustre.gleam b/src/lustre.gleam
index 77e0bb5..6c58c85 100644
--- a/src/lustre.gleam
+++ b/src/lustre.gleam
@@ -89,7 +89,7 @@ import gleam/otp/actor.{type StartError}
import gleam/result
import lustre/effect.{type Effect}
import lustre/element.{type Element, type Patch}
-import lustre/runtime
+import lustre/internals/runtime
// TYPES -----------------------------------------------------------------------
diff --git a/src/lustre/runtime.gleam b/src/lustre/internals/runtime.gleam
index 646baf4..646baf4 100644
--- a/src/lustre/runtime.gleam
+++ b/src/lustre/internals/runtime.gleam
diff --git a/src/lustre/server.gleam b/src/lustre/server.gleam
index cf6ebe6..1f7fef6 100644
--- a/src/lustre/server.gleam
+++ b/src/lustre/server.gleam
@@ -10,12 +10,12 @@ import lustre/attribute.{type Attribute, attribute}
import lustre/effect.{type Effect}
import lustre/element.{type Element, element}
import lustre/internals/constants
-import lustre/runtime.{type Action, Attrs, Event, SetSelector}
+import lustre/internals/runtime.{type Action, Attrs, Event, SetSelector}
// ELEMENTS --------------------------------------------------------------------
-/// A simple wrapper to render a `<lustre-server-component>` element.
-///
+/// A simple wrapper to render a `<lustre-server-component>` element.
+///
pub fn component(attrs: List(Attribute(msg))) -> Element(msg) {
element("lustre-server-component", attrs, [])
}
@@ -24,9 +24,9 @@ pub fn component(attrs: List(Attribute(msg))) -> Element(msg) {
/// The `route` attribute should always be included on a [`component`](#component)
/// to tell the client runtime what path to initiate the WebSocket connection on.
-///
-///
-///
+///
+///
+///
pub fn route(path: String) -> Attribute(msg) {
attribute("route", path)
}
@@ -34,25 +34,25 @@ pub fn route(path: String) -> Attribute(msg) {
/// Ocassionally you may want to attach custom data to an event sent to the server.
/// This could be used to include a hash of the current build to detect if the
/// event was sent from a stale client.
-///
+///
/// ```gleam
-///
+///
/// ```
-///
+///
pub fn data(json: Json) -> Attribute(msg) {
json
|> json.to_string
|> attribute("data-lustre-data", _)
}
-/// Properties of the JavaScript event object are typically not serialisable.
+/// Properties of the JavaScript event object are typically not serialisable.
/// This means if we want to pass them to the server we need to copy them into
/// a new object first.
-///
+///
/// This attribute tells Lustre what properties to include. Properties can come
/// from nested objects by using dot notation. For example, you could include the
/// `id` of the target `element` by passing `["target.id"]`.
-///
+///
/// ```gleam
/// import gleam/dynamic
/// import gleam/result.{try}
@@ -60,21 +60,21 @@ pub fn data(json: Json) -> Attribute(msg) {
/// import lustre/element/html
/// import lustre/event
/// import lustre/server
-///
+///
/// pub fn custom_button(on_click: fn(String) -> msg) -> Element(msg) {
/// let handler = fn(event) {
/// use target <- try(dynamic.field("target", dynamic.dynamic)(event))
/// use id <- try(dynamic.field("id", dynamic.string)(target))
-///
+///
/// Ok(on_click(id))
/// }
-///
+///
/// html.button([event.on_click(handler), server.include(["target.id"])], [
/// element.text("Click me!")
/// ])
/// }
/// ```
-///
+///
pub fn include(properties: List(String)) -> Attribute(msg) {
properties
|> json.array(json.string)
@@ -85,13 +85,13 @@ pub fn include(properties: List(String)) -> Attribute(msg) {
// EFFECTS ---------------------------------------------------------------------
///
-///
+///
pub fn emit(event: String, data: Json) -> Effect(msg) {
effect.event(event, data)
}
///
-///
+///
pub fn selector(sel: Selector(Action(runtime, msg))) -> Effect(msg) {
do_selector(sel)
}
diff --git a/test/lustre_test.gleam b/test/lustre_test.gleam
index c90dc8b..bae6c0f 100644
--- a/test/lustre_test.gleam
+++ b/test/lustre_test.gleam
@@ -10,7 +10,7 @@ import gleeunit
import lustre
import lustre/element
import lustre/internals/patch
-import lustre/runtime.{Debug, Dispatch, Shutdown, View}
+import lustre/internals/runtime.{Debug, Dispatch, Shutdown, View}
// MAIN ------------------------------------------------------------------------