Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
with:
otp-version: "27.0"
rebar3-version: "3"
gleam-version: "1.12.0"
gleam-version: "1.13.0"

- name: Check formatting
run: gleam format --check
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
with:
otp-version: "27.0"
rebar3-version: "3"
gleam-version: "1.12.0"
gleam-version: "1.13.0"

- run: |
version="v$(cat gleam.toml | grep -m 1 "version" | sed -r "s/version *= *\"([[:digit:].]+)\"/\1/")"
Expand Down
6 changes: 3 additions & 3 deletions src/lustre/component.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ pub fn new(options: List(Option(msg))) -> Config(msg) {
contexts: constants.empty_list,
//
is_form_associated: False,
on_form_autofill: constants.option_none,
on_form_reset: constants.option_none,
on_form_restore: constants.option_none,
on_form_autofill: option.None,
on_form_reset: option.None,
on_form_restore: option.None,
)

use config, option <- list.fold(options, init)
Expand Down
21 changes: 11 additions & 10 deletions src/lustre/dev/query.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import gleam/order
import gleam/string
import lustre/attribute
import lustre/element.{type Element}
import lustre/internals/constants
import lustre/vdom/path.{type Path}
import lustre/vdom/vattr.{Attribute}
import lustre/vdom/vnode.{Element, Fragment, Text, UnsafeInnerHtml}
Expand Down Expand Up @@ -267,7 +268,7 @@ pub fn find(
) -> Result(Element(msg), Nil) {
case find_path(in: root, matching: query, index: 0, from: path.root) {
Ok(#(element, _)) -> Ok(element)
Error(_) -> Error(Nil)
Error(_) -> constants.error_nil
}
}

Expand All @@ -290,13 +291,13 @@ pub fn find_path(
FindChild(of: parent, matching: selector) ->
case find_path(in: root, matching: parent, index:, from: path) {
Ok(#(element, path)) -> find_direct_child(element, selector, path)
Error(_) -> Error(Nil)
Error(_) -> constants.error_nil
}

FindDescendant(of: parent, matching: selector) ->
case find_path(in: root, matching: parent, index:, from: path) {
Ok(#(element, path)) -> find_descendant(element, selector, path)
Error(_) -> Error(Nil)
Error(_) -> constants.error_nil
}
}
}
Expand All @@ -310,8 +311,8 @@ fn find_in_children(
case element {
Element(children:, ..) | Fragment(children:, ..) ->
find_in_list(children, query, path |> path.add(index, element.key), 0)
UnsafeInnerHtml(..) -> Error(Nil)
Text(..) -> Error(Nil)
UnsafeInnerHtml(..) -> constants.error_nil
Text(..) -> constants.error_nil
}
}

Expand All @@ -322,7 +323,7 @@ fn find_in_list(
index: Int,
) -> Result(#(Element(msg), Path), Nil) {
case elements {
[] -> Error(Nil)
[] -> constants.error_nil

[first, ..rest] -> {
case find_path(in: first, matching: query, from: path, index:) {
Expand All @@ -342,7 +343,7 @@ fn find_direct_child(
Element(children:, ..) | Fragment(children:, ..) ->
find_matching_in_list(children, selector, path, 0)

UnsafeInnerHtml(..) | Text(..) -> Error(Nil)
UnsafeInnerHtml(..) | Text(..) -> constants.error_nil
}
}

Expand All @@ -353,7 +354,7 @@ fn find_matching_in_list(
index: Int,
) -> Result(#(Element(msg), Path), Nil) {
case elements {
[] -> Error(Nil)
[] -> constants.error_nil

[Fragment(..) as first, ..rest] ->
find_matching_in_list(
Expand Down Expand Up @@ -383,7 +384,7 @@ fn find_descendant(
Element(children:, ..) | Fragment(children:, ..) ->
find_descendant_in_list(children, selector, path, 0)

UnsafeInnerHtml(..) | Text(..) -> Error(Nil)
UnsafeInnerHtml(..) | Text(..) -> constants.error_nil
}
}
}
Expand All @@ -395,7 +396,7 @@ fn find_descendant_in_list(
index: Int,
) -> Result(#(Element(msg), Path), Nil) {
case elements {
[] -> Error(Nil)
[] -> constants.error_nil
[first, ..rest] -> {
case matches(first, selector) {
True -> Ok(#(first, path.add(path, index, first.key)))
Expand Down
4 changes: 3 additions & 1 deletion src/lustre/event.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,9 @@ fn formdata_decoder() -> Decoder(List(#(String, String))) {
// any `File` objects selected for file inputs. Our built-in `on_submit`
// handler only supports those string values so we decode into a `Result`
// so we can filter the files out without failing spectacularly.
decode.one_of(decode.map(decode.string, Ok), [decode.success(Error(Nil))]),
decode.one_of(decode.map(decode.string, Ok), [
decode.success(constants.error_nil),
]),
)

value
Expand Down
9 changes: 0 additions & 9 deletions src/lustre/internals/constants.ffi.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
import Dict from "../../../gleam_stdlib/dict.mjs";
import { new$ as set_new } from "../../../gleam_stdlib/gleam/set.mjs";

const EMPTY_DICT = /* @__PURE__ */ Dict.new();
const EMPTY_SET = /* @__PURE__*/ set_new();

export const empty_dict = () => EMPTY_DICT;
export const empty_set = () => EMPTY_SET;

export const document = () => globalThis?.document;

export const NAMESPACE_HTML = "http://www.w3.org/1999/xhtml";
Expand Down
16 changes: 1 addition & 15 deletions src/lustre/internals/constants.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,8 @@
//// references to them makes a huge difference over the lifetime of a program.
////

// IMPORTS ---------------------------------------------------------------------

import gleam/dict.{type Dict}
import gleam/option.{type Option, None}
import gleam/set.{type Set}

// CONSTRUCTORS ----------------------------------------------------------------

pub const empty_list = []

@external(erlang, "gleam@dict", "new")
@external(javascript, "./constants.ffi.mjs", "empty_dict")
pub fn empty_dict() -> Dict(k, v)

@external(erlang, "gleam@set", "new")
@external(javascript, "./constants.ffi.mjs", "empty_set")
pub fn empty_set() -> Set(a)

pub const option_none: Option(a) = None
pub const error_nil = Error(Nil)
13 changes: 4 additions & 9 deletions src/lustre/internals/mutable_map.ffi.mjs
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
import { Ok, Error } from "../../gleam.mjs";
import { Result$Ok } from "../../gleam.mjs";
import { error_nil } from "./constants.mjs";

export function empty() {
return null;
}

export function get(map, key) {
const value = map?.get(key);

if (value != null) {
return new Ok(value);
} else {
return new Error(undefined);
}
return value != null ? Result$Ok(value) : error_nil;
}

export function has_key(map, key) {
return map && map.has(key)
return map && map.has(key);
}

export function insert(map, key, value) {
Expand All @@ -34,4 +30,3 @@ export function remove(map, key) {
export function size(map) {
return map?.size ?? 0;
}

5 changes: 3 additions & 2 deletions src/lustre/runtime/server/runtime.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import gleam/otp/actor.{type Next, type StartError}
import gleam/result
import gleam/set.{type Set}
import lustre/effect.{type Effect}
import lustre/internals/constants
import lustre/runtime/transport.{type ClientMessage, type ServerMessage}
import lustre/vdom/diff.{Diff, diff}
import lustre/vdom/events.{type Events}
Expand Down Expand Up @@ -338,7 +339,7 @@ fn handle_attribute_change(
value: String,
) -> Result(msg, Nil) {
case dict.get(attributes, name) {
Error(_) -> Error(Nil)
Error(_) -> constants.error_nil
Ok(handler) -> handler(value)
}
}
Expand All @@ -349,7 +350,7 @@ fn handle_property_change(
value: Dynamic,
) -> Result(msg, Nil) {
case dict.get(properties, name) {
Error(_) -> Error(Nil)
Error(_) -> constants.error_nil
Ok(decoder) -> decode.run(value, decoder) |> result.replace_error(Nil)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/lustre/vdom/events.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ pub fn dispatch(events: Events(msg), event: DecodedEvent(msg)) {

case event {
DecodedEvent(handler:, path: _) -> #(events, Ok(handler))
DispatchedEvent(_) -> #(events, Error(Nil))
DispatchedEvent(_) -> #(events, constants.error_nil)
}
}

Expand Down