Skip to content

Commit eabb3d6

Browse files
committed
Use new Sketch and remove deprecated API
1 parent 6635d05 commit eabb3d6

File tree

9 files changed

+105
-125
lines changed

9 files changed

+105
-125
lines changed

.github/workflows/test.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ jobs:
1414
- uses: actions/checkout@v3
1515
- uses: erlef/setup-beam@v1
1616
with:
17-
otp-version: "26.0.2"
18-
gleam-version: "1.1.0"
19-
rebar3-version: "3"
17+
otp-version: '26.0.2'
18+
gleam-version: '1.4.0'
19+
rebar3-version: '3'
2020
# elixir-version: "1.15.4"
2121
- run: gleam deps download
2222
- run: gleam test

gleam.toml

+8-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
# https://gleam.run/writing-gleam/gleam-toml/.
33
name = "tardis"
44
target = "javascript"
5-
version = "0.1.0"
5+
version = "0.2.0"
6+
7+
gleam = ">= 1.4.0"
68

79
description = "Time traveller debugger, tailor-made for Lustre"
810
internal_modules = ["tardis/internals", "tardis/internals/*"]
@@ -11,10 +13,11 @@ links = [{title = "Sponsor", href = "https://github.com/sponsors/ghivert"}]
1113
repository = {type = "github", user = "ghivert", repo = "tardis"}
1214

1315
[dependencies]
14-
gleam_stdlib = ">= 0.36.0 and < 1.0.0"
15-
lustre = ">= 4.2.0 and < 5.0.0"
16-
plinth = ">= 0.2.0 and < 1.0.0"
17-
sketch = ">= 2.0.0 and < 3.0.0"
16+
gleam_stdlib = ">= 0.40.0 and < 1.0.0"
17+
lustre = ">= 4.3.1 and < 5.0.0"
18+
plinth = ">= 0.4.14 and < 1.0.0"
19+
sketch = ">= 3.1.0 and < 4.0.0"
20+
sketch_lustre = ">= 1.0.1 and < 2.0.0"
1821

1922
[dev-dependencies]
2023
gleeunit = ">= 1.1.2 and < 2.0.0"

manifest.toml

+17-13
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,25 @@
22
# You typically do not need to edit this file
33

44
packages = [
5-
{ name = "gleam_erlang", version = "0.25.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "054D571A7092D2A9727B3E5D183B7507DAB0DA41556EC9133606F09C15497373" },
6-
{ name = "gleam_javascript", version = "0.8.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_javascript", source = "hex", outer_checksum = "14D5B7E1A70681E0776BF0A0357F575B822167960C844D3D3FA114D3A75F05A8" },
5+
{ name = "conversation", version = "1.4.3", build_tools = ["gleam"], requirements = ["gleam_http", "gleam_javascript", "gleam_stdlib"], otp_app = "conversation", source = "hex", outer_checksum = "908B46F60444442785A495197D482558AD8B849C3714A38FAA1940358CC8CCCD" },
6+
{ name = "gleam_erlang", version = "0.27.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "DE468F676D71B313C6C8C5334425CFCF827837333F8AB47B64D8A6D7AA40185D" },
7+
{ name = "gleam_http", version = "3.7.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_http", source = "hex", outer_checksum = "EA66440C2269F7CED0F6845E5BD0DB68095775D627FA709A841CA78A398D6D56" },
8+
{ name = "gleam_javascript", version = "0.13.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_javascript", source = "hex", outer_checksum = "F98328FCF573DA6F3A35D7F6CB3F9FF19FD5224CCBA9151FCBEAA0B983AF2F58" },
79
{ name = "gleam_json", version = "1.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib", "thoas"], otp_app = "gleam_json", source = "hex", outer_checksum = "9063D14D25406326C0255BDA0021541E797D8A7A12573D849462CAFED459F6EB" },
8-
{ name = "gleam_otp", version = "0.10.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_stdlib"], otp_app = "gleam_otp", source = "hex", outer_checksum = "0B04FE915ACECE539B317F9652CAADBBC0F000184D586AAAF2D94C100945D72B" },
9-
{ name = "gleam_stdlib", version = "0.37.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "5398BD6C2ABA17338F676F42F404B9B7BABE1C8DC7380031ACB05BBE1BCF3742" },
10-
{ name = "gleeunit", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "72CDC3D3F719478F26C4E2C5FED3E657AC81EC14A47D2D2DEBB8693CA3220C3B" },
11-
{ name = "lustre", version = "4.2.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_json", "gleam_otp", "gleam_stdlib"], otp_app = "lustre", source = "hex", outer_checksum = "258F876CD7AB12C2C773F1A30F76DFC0A0ED989B720070DF32FC0717A6A0E60C" },
12-
{ name = "plinth", version = "0.2.0", build_tools = ["gleam"], requirements = ["gleam_javascript", "gleam_json", "gleam_stdlib"], otp_app = "plinth", source = "hex", outer_checksum = "83211E672D83F3CE14681D0ECD3AD883EE7588E423E7C9DDDB460014AD60AC24" },
13-
{ name = "sketch", version = "2.1.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_otp", "gleam_stdlib", "lustre", "plinth"], otp_app = "sketch", source = "hex", outer_checksum = "47175BD019A00CFEAAF2851830825544E24ABA58168083A1D219FA8E06EF6713" },
14-
{ name = "thoas", version = "1.2.0", build_tools = ["rebar3"], requirements = [], otp_app = "thoas", source = "hex", outer_checksum = "540C8CB7D9257F2AD0A14145DC23560F91ACDCA995F0CCBA779EB33AF5D859D1" },
10+
{ name = "gleam_otp", version = "0.12.1", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_stdlib"], otp_app = "gleam_otp", source = "hex", outer_checksum = "BFACC1513410DF5A1617169A9CD7EA334973AC71D860A17574BA7B2EADD89A6F" },
11+
{ name = "gleam_stdlib", version = "0.40.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "86606B75A600BBD05E539EB59FABC6E307EEEA7B1E5865AFB6D980A93BCB2181" },
12+
{ name = "gleeunit", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "F7A7228925D3EE7D0813C922E062BFD6D7E9310F0BEE585D3A42F3307E3CFD13" },
13+
{ name = "lustre", version = "4.5.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_json", "gleam_otp", "gleam_stdlib"], otp_app = "lustre", source = "hex", outer_checksum = "15C0597E97FBC4D095B6DDFAB849740EB9062828D55A071990A957C6564ADEF3" },
14+
{ name = "plinth", version = "0.4.14", build_tools = ["gleam"], requirements = ["conversation", "gleam_javascript", "gleam_json", "gleam_stdlib"], otp_app = "plinth", source = "hex", outer_checksum = "1954376A2E19735B251F73B33C5D119AEB838BD589475884710B224E402F1546" },
15+
{ name = "sketch", version = "3.1.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_otp", "gleam_stdlib"], otp_app = "sketch", source = "hex", outer_checksum = "F162070BCCF8BEF28C9520E80501565403E681D9E3F80844EC5ED307A2E4ADDF" },
16+
{ name = "sketch_lustre", version = "1.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib", "lustre", "plinth", "sketch"], otp_app = "sketch_lustre", source = "hex", outer_checksum = "9F3952F3574EE3D3269287D010AC9B131E48C8F2933AA6179D58851A866FEA3D" },
17+
{ name = "thoas", version = "1.2.1", build_tools = ["rebar3"], requirements = [], otp_app = "thoas", source = "hex", outer_checksum = "E38697EDFFD6E91BD12CEA41B155115282630075C2A727E7A6B2947F5408B86A" },
1518
]
1619

1720
[requirements]
18-
gleam_stdlib = { version = ">= 0.36.0 and < 1.0.0" }
21+
gleam_stdlib = { version = ">= 0.40.0 and < 1.0.0" }
1922
gleeunit = { version = ">= 1.1.2 and < 2.0.0" }
20-
lustre = { version = ">= 4.2.0 and < 5.0.0" }
21-
plinth = { version = ">= 0.2.0 and < 1.0.0" }
22-
sketch = { version = ">= 2.0.0 and < 3.0.0" }
23+
lustre = { version = ">= 4.3.1 and < 5.0.0" }
24+
plinth = { version = ">= 0.4.14 and < 1.0.0" }
25+
sketch = { version = ">= 3.1.0 and < 4.0.0" }
26+
sketch_lustre = { version = ">= 1.0.1 and < 2.0.0" }

src/tardis.ffi.mjs

+6-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function inspectCustomType(record) {
7373
return isNaN(parseInt(label))
7474
? [new Some(label + ': '), value]
7575
: [new None(), value]
76-
})
76+
}),
7777
)
7878
return new DataCustomType(record.constructor.name, props)
7979
}
@@ -88,7 +88,7 @@ export function inspectBitArray(bits) {
8888

8989
export function inspectUtfCodepoint(codepoint) {
9090
return new DataUtfCodepoint(
91-
`//utfcodepoint(${String.fromCodePoint(codepoint.value)})`
91+
`//utfcodepoint(${String.fromCodePoint(codepoint.value)})`,
9292
)
9393
}
9494

@@ -200,3 +200,7 @@ export function updateLustre(application, initMapper, updateMapper) {
200200
init: initMapper(application.init),
201201
})
202202
}
203+
204+
export function coerce(a) {
205+
return a
206+
}

src/tardis.gleam

+33-32
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
//// ```
4040

4141
import gleam/dynamic.{type Dynamic}
42-
import gleam/function
4342
import gleam/int
4443
import gleam/io
4544
import gleam/list
@@ -49,11 +48,11 @@ import gleam/result
4948
import lustre.{type Action, type App}
5049
import lustre/attribute as a
5150
import lustre/effect
52-
import lustre/element as el
53-
import lustre/element/html as h
5451
import lustre/event
55-
import sketch/lustre as sketch
56-
import sketch/options as sketch_options
52+
import sketch
53+
import sketch/lustre as sl
54+
import sketch/lustre/element as el
55+
import sketch/lustre/element/html as h
5756
import tardis/error
5857
import tardis/internals/data/colors
5958
import tardis/internals/data/debugger as debugger_
@@ -124,21 +123,13 @@ fn start_lustre(lustre_root, application) {
124123
|> result.map_error(error.LustreError)
125124
}
126125

127-
fn start_sketch(root) {
128-
// Attach the StyleSheet to the Shadow DOM.
129-
let setup = sketch.setup(sketch_options.shadow(root))
130-
use error <- result.map_error(setup)
131-
io.debug("Unable to start sketch. Check your configuration.")
132-
io.debug(error)
133-
error.SketchError(error)
134-
}
135-
136126
/// Creates the tardis. Should be run once, at the start of the application.
137127
/// It can be skipped when using [`single`](#single).
138128
pub fn setup() {
139129
let #(shadow_root, lustre_root) = setup.mount_shadow_node()
140-
start_sketch(shadow_root)
141-
|> result.map(sketch.compose(view, _))
130+
131+
sketch.cache(strategy: sketch.Ephemeral)
132+
|> result.map(sl.compose(sl.shadow(shadow_root), view, _))
142133
|> result.map(lustre.application(init, update, _))
143134
|> result.try(start_lustre(lustre_root, _))
144135
|> result.map(fn(dispatch) { Tardis(dispatch) })
@@ -184,7 +175,7 @@ fn update(model: Model, msg: Msg) {
184175
let fst_step = list.first(d.steps)
185176
use step <- result.try(fst_step)
186177
d.dispatcher
187-
|> option.map(function.apply1(_, step.model))
178+
|> option.map(fn(d) { d(step.model) })
188179
|> option.to_result(Nil)
189180
})
190181
|> effect.batch()
@@ -212,7 +203,7 @@ fn update(model: Model, msg: Msg) {
212203
|> debugger_.get(debugger_)
213204
|> result.try(fn(d) {
214205
d.dispatcher
215-
|> option.map(function.apply1(_, item.model))
206+
|> option.map(fn(d) { d(item.model) })
216207
|> option.to_result(Nil)
217208
})
218209
|> result.unwrap(effect.none())
@@ -262,19 +253,19 @@ fn color_scheme_selector(model: Model) {
262253
case model.opened {
263254
False -> el.none()
264255
True ->
265-
h.select([event.on_input(on_cs_input), s.select_cs()], {
256+
h.select(s.select_cs(), [event.on_input(on_cs_input)], {
266257
use item <- list.map(colors.themes())
267258
let as_s = colors.cs_to_string(item)
268259
let selected = model.color_scheme == item
269-
h.option([a.value(as_s), a.selected(selected)], as_s)
260+
h.option_([a.value(as_s), a.selected(selected)], [h.text(as_s)])
270261
})
271262
}
272263
}
273264

274265
fn restart_button(model: Model) {
275266
case model.frozen, model.selected_debugger {
276267
True, Some(debugger_) ->
277-
h.button([s.select_cs(), event.on_click(msg.Restart(debugger_))], [
268+
h.button(s.select_cs(), [event.on_click(msg.Restart(debugger_))], [
278269
h.text("Restart"),
279270
])
280271
_, _ -> el.none()
@@ -286,31 +277,41 @@ fn view(model: Model) {
286277
let #(panel, header, button_txt) = select_panel_options(model.opened)
287278
let frozen_panel = case model.frozen {
288279
True -> s.frozen_panel()
289-
False -> a.none()
280+
False -> sketch.class([])
290281
}
291282
let debugger_ =
292283
model.selected_debugger
293284
|> option.unwrap("")
294285
|> debugger_.get(model.debuggers, _)
295-
h.div([a.class("debugger_"), color_scheme_class, frozen_panel], [
296-
h.div([panel], [
297-
h.div([header], [
298-
h.div([s.flex(), s.debugger_title()], [
299-
h.div([], [h.text("Debugger")]),
286+
let panel_class =
287+
[color_scheme_class, frozen_panel]
288+
|> list.map(sketch.compose)
289+
|> sketch.class
290+
let title_class =
291+
[s.flex(), s.debugger_title()]
292+
|> list.map(sketch.compose)
293+
|> sketch.class
294+
h.div(panel_class, [a.class("debugger_")], [
295+
h.div(panel, [], [
296+
h.div(header, [], [
297+
h.div(title_class, [], [
298+
h.div_([], [h.text("Debugger")]),
300299
color_scheme_selector(model),
301300
restart_button(model),
302301
]),
303302
case debugger_ {
304303
Error(_) -> el.none()
305304
Ok(debugger_) ->
306-
h.div([s.actions_section()], [
307-
h.select([event.on_input(on_debugger_input), s.select_cs()], {
305+
h.div(s.actions_section(), [], [
306+
h.select(s.select_cs(), [event.on_input(on_debugger_input)], {
308307
use #(item, _) <- list.map(model.keep_active_debuggers(model))
309308
let selected = model.selected_debugger == Some(item)
310-
h.option([a.value(item), a.selected(selected)], item)
309+
h.option_([a.value(item), a.selected(selected)], [h.text(item)])
311310
}),
312-
h.div([], [h.text(int.to_string(debugger_.count - 1) <> " Steps")]),
313-
h.button([s.toggle_button(), event.on_click(msg.ToggleOpen)], [
311+
h.div_([], [
312+
h.text(int.to_string(debugger_.count - 1) <> " Steps"),
313+
]),
314+
h.button(s.toggle_button(), [event.on_click(msg.ToggleOpen)], [
314315
h.text(button_txt),
315316
]),
316317
])

src/tardis/internals/data/colors.gleam

-5
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ pub fn ayu_dark_class() {
194194
sketch.property("--regex", ayu_dark.regex),
195195
sketch.property("--date", ayu_dark.date),
196196
])
197-
|> sketch.to_lustre()
198197
}
199198

200199
pub fn ayu_light_class() {
@@ -219,7 +218,6 @@ pub fn ayu_light_class() {
219218
sketch.property("--regex", ayu_light.regex),
220219
sketch.property("--date", ayu_light.date),
221220
])
222-
|> sketch.to_lustre()
223221
}
224222

225223
pub fn catpuccin_light_class() {
@@ -244,7 +242,6 @@ pub fn catpuccin_light_class() {
244242
sketch.property("--regex", catpuccin_light.regex),
245243
sketch.property("--date", catpuccin_light.date),
246244
])
247-
|> sketch.to_lustre()
248245
}
249246

250247
pub fn catpuccin_frappe_class() {
@@ -269,7 +266,6 @@ pub fn catpuccin_frappe_class() {
269266
sketch.property("--regex", catpuccin_frappe.regex),
270267
sketch.property("--date", catpuccin_frappe.date),
271268
])
272-
|> sketch.to_lustre()
273269
}
274270

275271
pub fn gleam_class() {
@@ -294,7 +290,6 @@ pub fn gleam_class() {
294290
sketch.property("--regex", gleam.regex),
295291
sketch.property("--date", gleam.date),
296292
])
297-
|> sketch.to_lustre()
298293
}
299294

300295
pub fn choose_color_scheme() {

src/tardis/internals/setup.gleam

+11-12
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ pub type Middleware =
1515
@external(javascript, "../../tardis.ffi.mjs", "addCustomStyles")
1616
fn add_custom_styles(content: String) -> Nil
1717

18+
@external(javascript, "../../tardis.ffi.mjs", "coerce")
19+
fn coerce(content: Dynamic) -> a
20+
1821
pub fn instanciate_shadow_root(element: Element) {
1922
// Instanciate the Shadow DOM wrapper.
2023
let div = document.create_element("div")
@@ -39,7 +42,7 @@ pub fn mount_shadow_node() {
3942
let shadow_root = instanciate_shadow_root(lustre_root_)
4043
// Trick to fool lustre application.
4144
// Please children, don't do this at home.
42-
let lustre_root: String = dynamic.unsafe_coerce(dynamic.from(lustre_root_))
45+
let lustre_root: String = coerce(dynamic.from(lustre_root_))
4346
#(shadow_root, lustre_root)
4447
}
4548

@@ -84,17 +87,14 @@ pub fn create_model_updater(
8487
) {
8588
fn(dispatcher: Dynamic) {
8689
fn(model: Dynamic) -> Effect(Msg) {
87-
effect.from(fn(_) {
88-
model
89-
|> dynamic.from()
90-
|> runtime.ForceModel()
91-
|> runtime.Debug()
92-
|> dynamic.unsafe_coerce(dispatcher)
93-
})
90+
use _ <- effect.from
91+
let model = dynamic.from(model)
92+
let msg = runtime.Debug(runtime.ForceModel(model))
93+
coerce(dispatcher)(msg)
9494
}
9595
|> msg.AddApplication(application, _)
96-
|> lustre.dispatch()
97-
|> dispatch()
96+
|> lustre.dispatch
97+
|> dispatch
9898
}
9999
}
100100

@@ -103,8 +103,7 @@ pub fn step_adder(
103103
name: String,
104104
) {
105105
fn(model, msg) {
106-
model
107-
|> msg.AddStep(name, _, msg)
106+
msg.AddStep(name, model, msg)
108107
|> lustre.dispatch()
109108
|> dispatch()
110109
}

0 commit comments

Comments
 (0)