Skip to content

Commit

Permalink
Fix: Passing property to mutable component argument
Browse files Browse the repository at this point in the history
  • Loading branch information
Arpita-Jaiswal committed Oct 19, 2023
1 parent d72eb32 commit 6b571ff
Show file tree
Hide file tree
Showing 5 changed files with 194 additions and 6 deletions.
6 changes: 3 additions & 3 deletions fastn-js/src/component_invocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub enum ElementKind {
#[derive(Debug)]
pub struct InstantiateComponent {
pub component: InstantiateComponentData,
pub arguments: Vec<(String, fastn_js::SetPropertyValue)>,
pub arguments: Vec<(String, fastn_js::SetPropertyValue, bool)>,
pub parent: String,
pub inherited: String,
pub should_return: bool,
Expand All @@ -66,7 +66,7 @@ pub enum InstantiateComponentData {
impl InstantiateComponent {
pub fn new(
component_name: &str,
arguments: Vec<(String, fastn_js::SetPropertyValue)>,
arguments: Vec<(String, fastn_js::SetPropertyValue, bool)>,
parent: &str,
inherited: &str,
should_return: bool,
Expand All @@ -86,7 +86,7 @@ impl InstantiateComponent {

pub fn new_with_definition(
component_definition: fastn_js::SetPropertyValue,
arguments: Vec<(String, fastn_js::SetPropertyValue)>,
arguments: Vec<(String, fastn_js::SetPropertyValue, bool)>,
parent: &str,
inherited: &str,
should_return: bool,
Expand Down
12 changes: 10 additions & 2 deletions fastn-js/src/to_js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,16 @@ impl fastn_js::InstantiateComponent {
text("{")
.append(
pretty::RcDoc::intersperse(
self.arguments.iter().map(|(k, v)| {
format!("{}: {}", fastn_js::utils::name_to_js_(k), v.to_js())
self.arguments.iter().map(|(k, value, is_mutable)| {
format!(
"{}: {}",
fastn_js::utils::name_to_js_(k),
if *is_mutable {
format!("fastn.mutable({})", value.to_js())
} else {
value.to_js()
}
)
}),
comma().append(space()),
)
Expand Down
3 changes: 2 additions & 1 deletion ftd/src/js/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ pub(crate) fn get_set_property_values_for_provided_component_properties(
component_properties: &[ftd::interpreter::Property],
line_number: usize,
has_rive_components: &mut bool,
) -> Option<Vec<(String, fastn_js::SetPropertyValue)>> {
) -> Option<Vec<(String, fastn_js::SetPropertyValue, bool)>> {
use itertools::Itertools;

// Attempt to retrieve component or web component arguments
Expand All @@ -280,6 +280,7 @@ pub(crate) fn get_set_property_values_for_provided_component_properties(
has_rive_components,
false,
),
v.mutable,
)
})
})
Expand Down
26 changes: 26 additions & 0 deletions ftd/t/js/65-counter.ftd
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
-- counter:
$count: 10

/-- counter: 10

-- component counter:
caption integer $count: 20

-- ftd.row:
border-width.px: 2
padding.px: 20
spacing.fixed.px: 20
background.solid if { counter.count % 2 == 0 }: yellow
border-radius.px: 5

-- ftd.text: ➕
$on-click$: $ftd.increment-by($a=$counter.count, v=1)

-- ftd.integer: $counter.count

-- ftd.text: ➖
$on-click$: $ftd.increment-by($a=$counter.count, v=-1)

-- end: ftd.row

-- end: counter
153 changes: 153 additions & 0 deletions ftd/t/js/65-counter.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6b571ff

Please sign in to comment.