Skip to content

Commit 8cf74e5

Browse files
committed
Remove Fragment from sketch_lustre
1 parent 17d6841 commit 8cf74e5

File tree

3 files changed

+26
-38
lines changed

3 files changed

+26
-38
lines changed

sketch_lustre/src/sketch/internals/ffi.gleam

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import gleam/dynamic.{type Dynamic}
2+
import plinth/browser/shadow.{type ShadowRoot}
3+
14
pub opaque type Mutable(a) {
25
Mutable(value: a)
36
}
@@ -8,11 +11,26 @@ pub fn wrap(value: a) -> Mutable(a) {
811
}
912

1013
@external(javascript, "../../sketch_lustre.ffi.mjs", "set")
11-
pub fn set(variable: Mutable(a), value: a) -> Mutable(a) {
14+
pub fn set(_variable: Mutable(a), value: a) -> Mutable(a) {
1215
Mutable(value: value)
1316
}
1417

1518
@external(javascript, "../../sketch_lustre.ffi.mjs", "get")
1619
pub fn get(variable: Mutable(a)) -> a {
1720
variable.value
1821
}
22+
23+
@external(javascript, "../../sketch_lustre.ffi.mjs", "createCssStyleSheet")
24+
pub fn create_document_stylesheet() -> Dynamic {
25+
dynamic.from(0)
26+
}
27+
28+
@external(javascript, "../../sketch_lustre.ffi.mjs", "createCssStyleSheet")
29+
pub fn create_shadow_root_stylesheet(_root: ShadowRoot) -> Dynamic {
30+
dynamic.from(0)
31+
}
32+
33+
@external(javascript, "../../sketch_lustre.ffi.mjs", "setStylesheet")
34+
pub fn set_stylesheet(_content: String, _stylesheet: Dynamic) -> Nil {
35+
Nil
36+
}

sketch_lustre/src/sketch/lustre.gleam

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,6 @@ import sketch.{type Cache}
88
import sketch/internals/ffi
99
import sketch/lustre/element
1010

11-
@external(javascript, "../sketch_lustre.ffi.mjs", "createCssStyleSheet")
12-
fn create_document_stylesheet() -> Dynamic
13-
14-
@external(javascript, "../sketch_lustre.ffi.mjs", "createCssStyleSheet")
15-
fn create_shadow_root_stylesheet(root: ShadowRoot) -> Dynamic
16-
17-
@external(javascript, "../sketch_lustre.ffi.mjs", "setStylesheet")
18-
fn set_stylesheet(content: String, stylesheet: Dynamic) -> Nil {
19-
Nil
20-
}
21-
2211
type StyleSheetOption {
2312
Node
2413
Document
@@ -57,16 +46,17 @@ pub fn compose(
5746
}
5847

5948
@target(erlang)
60-
fn to_stylesheet(options) {
49+
fn to_stylesheet(_options) {
6150
NodeStyleSheet
6251
}
6352

6453
@target(javascript)
6554
fn to_stylesheet(options) {
6655
case options {
6756
Options(Node) -> NodeStyleSheet
68-
Options(Document) -> CssStyleSheet(create_document_stylesheet())
69-
Options(Shadow(root)) -> CssStyleSheet(create_shadow_root_stylesheet(root))
57+
Options(Document) -> CssStyleSheet(ffi.create_document_stylesheet())
58+
Options(Shadow(root)) ->
59+
CssStyleSheet(ffi.create_shadow_root_stylesheet(root))
7060
}
7161
}
7262

@@ -81,7 +71,7 @@ fn render_stylesheet(content, node, stylesheet) {
8171
}
8272
}
8373
CssStyleSheet(stylesheet) -> {
84-
set_stylesheet(content, stylesheet)
74+
ffi.set_stylesheet(content, stylesheet)
8575
node
8676
}
8777
}

sketch_lustre/src/sketch/lustre/element.gleam

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import gleam/int
21
import gleam/list
32
import gleam/option
43
import gleam/pair
@@ -10,7 +9,6 @@ import sketch.{type Cache}
109
pub opaque type Element(msg) {
1110
Nothing
1211
Text(content: String)
13-
Fragment(key: String, children: List(Element(msg)))
1412
Map(subtree: fn() -> Element(msg))
1513
Element(
1614
key: String,
@@ -69,7 +67,8 @@ pub fn namespaced_(
6967
}
7068

7169
pub fn fragment(children: List(Element(msg))) {
72-
Fragment("", children)
70+
let attrs = [attribute.style([#("display", "contents")])]
71+
Element("", "", "lustre-fragment", option.None, attrs, children)
7372
}
7473

7574
pub fn keyed(
@@ -87,21 +86,6 @@ fn do_keyed(element: Element(msg), key: String) {
8786
Nothing -> Nothing
8887
Text(content) -> Text(content)
8988
Map(subtree) -> Map(fn() { do_keyed(subtree(), key) })
90-
Fragment(_, children) ->
91-
children
92-
|> list.index_map(fn(element, idx) {
93-
case element {
94-
Element(el_key, _, _, _, _, _) -> {
95-
let new_key = case el_key {
96-
"" -> key <> "-" <> int.to_string(idx)
97-
_ -> key <> "-" <> el_key
98-
}
99-
do_keyed(element, new_key)
100-
}
101-
_ -> do_keyed(element, key)
102-
}
103-
})
104-
|> Fragment(key, _)
10589
Element(_, namespace, tag, attributes, children, styles) ->
10690
Element(key, namespace, tag, attributes, children, styles)
10791
}
@@ -112,7 +96,6 @@ pub fn map(element: Element(a), mapper: fn(a) -> b) {
11296
Nothing -> Nothing
11397
Text(content) -> Text(content)
11498
Map(subtree) -> Map(fn() { map(subtree(), mapper) })
115-
Fragment(key, children) -> Fragment(key, list.map(children, map(_, mapper)))
11699
Element(key, namespace, tag, class, attributes, children) -> {
117100
let attributes = list.map(attributes, attribute.map(_, mapper))
118101
let children = list.map(children, map(_, mapper))
@@ -137,9 +120,6 @@ pub fn unstyled(cache: Cache, element: Element(msg)) {
137120
Nothing -> #(cache, el.none())
138121
Text(content) -> #(cache, el.text(content))
139122
Map(subtree) -> unstyled(cache, subtree())
140-
Fragment(_, children) ->
141-
unstyled_children(cache, children)
142-
|> pair.map_second(fn(node) { el.fragment(node) })
143123
Element(key, namespace, tag, class, attributes, children) -> {
144124
let class = option.map(class, sketch.class_name(_, cache))
145125
let class_name = option.map(class, pair.second)

0 commit comments

Comments
 (0)