Skip to content

Commit

Permalink
get a text_node short hand; tag 0.0.16
Browse files Browse the repository at this point in the history
  • Loading branch information
tiye committed Nov 26, 2024
1 parent 44f103f commit a3b5ddf
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 22 deletions.
4 changes: 2 additions & 2 deletions moon.mod.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tiye/respo",
"version": "0.0.15",
"version": "0.0.16",
"deps": {
"tiye/dom-ffi": "0.0.6",
"tiye/cirru-parser": "0.0.7"
Expand All @@ -9,6 +9,6 @@
"repository": "https://github.com/Respo/respo.mbt/",
"license": "Apache-2.0",
"keywords": ["virtual-dom"],
"description": "A tiny virtual DOM library(preview mode)",
"description": "A tiny virtual DOM library(beta)",
"source": "src"
}
14 changes: 14 additions & 0 deletions src/lib/node/alias.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,20 @@ pub fn span[T](
)
}

/// internally using span element to render text.
pub fn text_node[T](
class_name? : String,
style? : RespoStyle,
text : String
) -> RespoNode[T] {
span(
inner_text=text,
class_name=class_name.or_default(),
style=style.or_default(),
[],
)
}

pub fn button[T](
class_name? : String,
inner_text~ : String,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/node/css.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,7 @@ pub fn declare_static_style[U : Show](
}
style_tag.set_inner_html(styles)
head.reinterpret_as_node().append_child(style_tag.reinterpret_as_node())
class_name_in_tags.insert(gen_name)
class_name_in_tags.add(gen_name)
gen_name
}
}
6 changes: 3 additions & 3 deletions src/lib/node/diff.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub fn diff_tree[T](
let skipped : @hashset.T[Int] = @hashset.new()
for idx, effect in effects {
match old_effects.get(idx) {
Some(old_effect) => if effect == old_effect { skipped.insert(idx) }
Some(old_effect) => if effect == old_effect { skipped.add(idx) }
None => ()
}
}
Expand Down Expand Up @@ -166,7 +166,7 @@ fn diff_attrs[T](
for pair in old_attrs.iter() {
let (key, _) = pair
if not(new_attrs.contains(key)) {
removed.insert(key)
removed.add(key)
if inner_changed(key) {
reset_inner.val = true
}
Expand Down Expand Up @@ -204,7 +204,7 @@ fn diff_style[T](
for pair in old_style {
let (key, _) = pair
if not(new_style.contains(key)) {
removed.insert(key)
removed.add(key)
}
}
if not(added.is_empty()) || not(removed.is_empty()) {
Expand Down
12 changes: 4 additions & 8 deletions src/main/counter.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,21 @@ fn comp_counter(
),
@respo_node.div(
[
@respo_node.span(
inner_text="value is: " + counted.to_string(),
@respo_node.text_node(
"value is: " + counted.to_string(),
style=respo_style(
color=Hsluv(270, 100, 40),
font_family="Menlo",
font_size=counted.reinterpret_as_uint() + 10,
),
[],
),
],
),
@respo_node.div(
[
@respo_node.span(inner_text="local state: \{counted}", []),
text_node("local state: \{counted}"),
@respo_node.br(),
@respo_node.span(
inner_text="global state: " + global_counted.to_string(),
[],
),
text_node("global state: " + global_counted.to_string()),
],
),
],
Expand Down
3 changes: 2 additions & 1 deletion src/main/moon.pkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"input",
"button",
"declare_static_style",
"respo_style"
"respo_style",
"text_node"
]
},
{ "path": "tiye/respo/lib/dialog", "alias": "dialog" },
Expand Down
2 changes: 1 addition & 1 deletion src/main/panel.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ fn comp_panel(
inner_text="add",
event={}..set(Click, on_submit),
),
span(inner_text="got panel state: \{state.to_json()}", []),
text_node("got panel state: \{state.to_json()}"),
],
),
)
Expand Down
8 changes: 2 additions & 6 deletions src/main/plugins.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ fn comp_plugins_demo(
@respo_node.div(
style=respo_style(padding=Px(8)),
[
@respo_node.div(
[@respo_node.span(inner_text="content in custom modal", [])],
),
@respo_node.div([text_node("content in custom modal")]),
@respo_node.div(
class_name=@respo.ui_row_parted,
[
Expand Down Expand Up @@ -141,9 +139,7 @@ fn comp_plugins_demo(
@respo_node.div(
style=respo_style(padding=Px(8)),
[
@respo_node.div(
[@respo_node.span(inner_text="content in custom drawer", [])],
),
@respo_node.div([text_node("content in custom drawer")]),
@respo_node.div(
attrs=@respo_node.respo_attrs(class_name=@respo.ui_row_parted),
[
Expand Down

0 comments on commit a3b5ddf

Please sign in to comment.