Skip to content

Commit

Permalink
feat: support tag attr update
Browse files Browse the repository at this point in the history
  • Loading branch information
meloalright committed Feb 27, 2024
1 parent 80efe5f commit 67ff72c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
11 changes: 11 additions & 0 deletions rustle/src/compiler/generate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,17 @@ fn traverse(node: &Fragment, parent: String, analysis: &AnalysisResult, code: &m
"{}.{} = {};",
parent, attr.name, value
));

if analysis.will_change.contains(&value) {
code.update.push(format!(
r#"
if (changed.includes('{}')) {{
{}.{} = {};
}}
"#,
value, parent, attr.name, value
));
}
}
}

Expand Down
1 change: 1 addition & 0 deletions rustle/tests/tag_update/app.rustle
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@

<button on:click={update_url} />
<div>{url}</div>
<div x={url} />
4 changes: 2 additions & 2 deletions rustle/tests/test_parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ fn test_parsing_reactive_assignments() { test_parsing("reactive-assignments".to_
#[test]
fn test_parsing_nested() { test_parsing("nested".to_owned()) }

// #[test]
// fn test_tag_update() { test_parsing("tag_update".to_owned()) }
#[test]
fn test_tag_update() { test_parsing("tag_update".to_owned()) }

0 comments on commit 67ff72c

Please sign in to comment.