Skip to content

Commit

Permalink
🚚 Move runtime module into internals/.
Browse files Browse the repository at this point in the history
  • Loading branch information
hayleigh-dot-dev committed Jan 27, 2024
1 parent afb57d6 commit dcad7a4
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 21 deletions.
1 change: 0 additions & 1 deletion gleam.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ gleam = ">= 0.33.0"
internal_modules = [
"lustre/internals",
"lustre/internals/*",
"lustre/runtime",
"lustre/try",
]

Expand Down
Binary file added priv/bin/esbuild
Binary file not shown.
2 changes: 1 addition & 1 deletion src/lustre.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -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 -----------------------------------------------------------------------

Expand Down
File renamed without changes.
36 changes: 18 additions & 18 deletions src/lustre/server.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -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, [])
}
Expand All @@ -24,57 +24,57 @@ 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)
}

/// 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}
/// import lustre/element.{type Element}
/// 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)
Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion test/lustre_test.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -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 ------------------------------------------------------------------------

Expand Down

0 comments on commit dcad7a4

Please sign in to comment.