Skip to content

Commit aa15d30

Browse files
authored
Merge pull request #17 from elcharitas/feat/reactivity-improvements-and-diff-patching
2 parents 6f342d6 + 94a70d3 commit aa15d30

File tree

8 files changed

+1123
-187
lines changed

8 files changed

+1123
-187
lines changed

docs/src/main.rs

Lines changed: 463 additions & 80 deletions
Large diffs are not rendered by default.

momenta-macros/src/lib.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -172,22 +172,18 @@ fn parse_attribute_name(input: ParseStream) -> Result<(Ident, Span)> {
172172
/// // Support for let patterns in conditions (if let style)
173173
/// when!(let Some(value) = option_value => <div>{value}</div>);
174174
/// when!(let Ok(val) = result => <div>"Success: "{val}</div> else <div>"Error"</div>);
175-
/// when!(let Some(x) = get_option() => format!("Got: {}", x) else "Nothing".to_string());
175+
/// // when!(let Some(x) = get_option() => format!("Got: {}", x) else ("Nothing".to_string()));
176176
///
177177
/// // Support for blocks as values
178+
/// let condition = true;
178179
/// when!(condition => {
179180
/// let msg = "Complex computation";
180181
/// format!("{} result", msg)
181182
/// });
182183
///
183184
/// // Support for arrays/vectors as values
184-
/// when!(show_list => [1, 2, 3, 4] else []);
185-
///
186-
/// // Match syntax
187-
/// when!(result {
188-
/// Ok(val) => <div>{val}</div>,
189-
/// Err(_) => <p>"Error occurred"</p>
190-
/// });
185+
/// let show_list = false;
186+
/// when!(show_list => [1, 2, 3, 4] else [0, 8, 4, 6]);
191187
/// ```
192188
#[proc_macro]
193189
pub fn when(input: TokenStream) -> TokenStream {
@@ -506,7 +502,7 @@ pub fn derive_signal_value(input: TokenStream) -> TokenStream {
506502
///
507503
/// # Examples
508504
///
509-
/// ```rust
505+
/// ```rust ignore
510506
/// use momenta::prelude::*;
511507
/// // Fragment
512508
/// rsx!(<>"Hello World"</>);
@@ -530,7 +526,6 @@ pub fn derive_signal_value(input: TokenStream) -> TokenStream {
530526
/// // Keyword attributes (automatically converted with _ suffix)
531527
/// rsx!(<input type="text" for="name" />);
532528
/// ```
533-
534529
#[proc_macro]
535530
pub fn rsx(input: TokenStream) -> TokenStream {
536531
let input = parse_macro_input!(input as RsxNode);
@@ -662,7 +657,7 @@ impl Parse for RsxChildren {
662657
let gap_size = start - last_end;
663658
if gap_size > 0 && last_end > 0 {
664659
// Add spaces to represent the gap
665-
value.push_str(&" ".repeat(gap_size as usize));
660+
value.push_str(&" ".repeat(gap_size));
666661
}
667662
}
668663
value.push_str(&token.to_string());
@@ -799,8 +794,9 @@ impl Parse for RsxNode {
799794
return Err(syn::Error::new(
800795
close_tag.span(),
801796
format!(
802-
"Closing tag </{}> doesn't match opening tag <{}>",
803-
close_tag, tag
797+
"Closing tag </{}> doesn't match opening tag <{}>\n\
798+
help: change the closing tag to </{}>",
799+
close_tag, tag, tag
804800
),
805801
));
806802
}
@@ -840,7 +836,12 @@ impl Parse for RsxNode {
840836
Ok(block) => Ok(RsxNode::Block(block)),
841837
Err(_) => Err(syn::Error::new(
842838
Span::call_site(),
843-
"Invalid JSX node, expected a valid rsx block, an expression or plain text",
839+
"Invalid RSX syntax\n\
840+
help: expected one of:\n\
841+
- an HTML element: <div>...</div>\n\
842+
- a string literal: \"text\"\n\
843+
- an expression: {value}\n\
844+
- a fragment: <>...</>",
844845
)),
845846
}
846847
}
@@ -869,7 +870,7 @@ impl RsxNode {
869870
quote_spanned! { span=> #v}
870871
})
871872
.or_else(|| Some(quote! {true}));
872-
(name, value, span.clone())
873+
(name, value, *span)
873874
});
874875

875876
let data_props = (is_element
@@ -929,7 +930,7 @@ impl RsxNode {
929930
quote_spanned! {span=> #name: {#value}.into(), }
930931
});
931932

932-
let children_tokens = if children.len() > 0 || is_element {
933+
let children_tokens = if !children.is_empty() || is_element {
933934
let child_tokens = children.iter().map(|child| child.to_tokens());
934935
Some(quote_spanned! { *open_span=>
935936
children: vec![#(#child_tokens),*],

momenta/Cargo.toml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,20 @@ web-sys = { version = "0.3", optional = true, features = [
2222
"HtmlElement",
2323
"Window",
2424
"Event",
25+
"NamedNodeMap",
26+
"Attr",
2527
] }
2628

2729
[features]
28-
default = []
30+
default = ["full-elements", "full-reactivity", "wasm"]
2931
wasm = ["wasm-bindgen", "wasm-bindgen-futures", "web-sys"]
32+
# Enable all HTML elements (default)
33+
full-elements = []
34+
# Minimal set of common HTML elements
35+
minimal-elements = []
36+
# Enable computed signals
37+
computed = []
38+
# Enable memoization
39+
memoization = []
40+
# Enable all reactivity features
41+
full-reactivity = ["computed", "memoization"]

0 commit comments

Comments
 (0)