From 236011d17c48d17c00ebaf25e85a65b13f29ec68 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Tue, 25 May 2021 15:46:14 +0200 Subject: [PATCH] Make ComponentDefinition::properties only list the public properties as it should Fixes #242 --- CHANGELOG.md | 1 + api/sixtyfps-cpp/tests/interpreter.cpp | 17 +++++++++++++ sixtyfps_runtime/interpreter/api.rs | 24 +++++++++++++++++++ .../interpreter/dynamic_component.rs | 7 ++++-- 4 files changed, 47 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4570dd4a9..5aabba77f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ All notable changes to this project will be documented in this file. - Fixed C++ backend on windows - `debug(...)` no longer break the LSP + - ComponentDefinition::properties only expose public properties as documented - Many more bugfixes diff --git a/api/sixtyfps-cpp/tests/interpreter.cpp b/api/sixtyfps-cpp/tests/interpreter.cpp index 20a945cc1..9ef4c598b 100644 --- a/api/sixtyfps-cpp/tests/interpreter.cpp +++ b/api/sixtyfps-cpp/tests/interpreter.cpp @@ -314,6 +314,23 @@ SCENARIO("Component Definition Properties") REQUIRE(properties[0].property_type == Value::Type::String); } +SCENARIO("Component Definition Properties / Two-way bindings") +{ + using namespace sixtyfps::interpreter; + using namespace sixtyfps; + + ComponentCompiler compiler; + auto comp_def = *compiler.build_from_source( + "export Dummy := Rectangle { property test <=> sub_object.test; " + " sub_object := Rectangle { property test; }" + "}", + ""); + auto properties = comp_def.properties(); + REQUIRE(properties.size() == 1); + REQUIRE(properties[0].property_name == "test"); + REQUIRE(properties[0].property_type == Value::Type::String); +} + SCENARIO("Invoke callback") { using namespace sixtyfps::interpreter; diff --git a/sixtyfps_runtime/interpreter/api.rs b/sixtyfps_runtime/interpreter/api.rs index d5867cdaf..a49d8e7eb 100644 --- a/sixtyfps_runtime/interpreter/api.rs +++ b/sixtyfps_runtime/interpreter/api.rs @@ -909,6 +909,30 @@ fn component_definition_properties() { assert_eq!(props[0].1, ValueType::String); } +#[test] +fn component_definition_properties2() { + let mut compiler = ComponentCompiler::new(); + let comp_def = spin_on::spin_on( + compiler.build_from_source( + r#" + export Dummy := Rectangle { + property sub-text <=> sub.text; + sub := Text { property private-not-exported; } + callback hello; + }"# + .into(), + "".into(), + ), + ) + .unwrap(); + + let props = comp_def.properties().collect::>(); + + assert_eq!(props.len(), 1); + assert_eq!(props[0].0, "sub_text"); + assert_eq!(props[0].1, ValueType::String); +} + #[cfg(feature = "ffi")] #[allow(missing_docs)] #[path = "ffi.rs"] diff --git a/sixtyfps_runtime/interpreter/dynamic_component.rs b/sixtyfps_runtime/interpreter/dynamic_component.rs index 3948f35e1..fb0e84df8 100644 --- a/sixtyfps_runtime/interpreter/dynamic_component.rs +++ b/sixtyfps_runtime/interpreter/dynamic_component.rs @@ -313,8 +313,11 @@ impl<'id> ComponentDescription<'id> { /// List of publicly declared properties or callbacks pub fn properties( &self, - ) -> impl ExactSizeIterator + '_ { - self.public_properties.iter().map(|(s, v)| (s.clone(), v.property_type.clone())) + ) -> impl Iterator + '_ { + self.public_properties + .iter() + .filter(|(_, v)| v.expose_in_public_api) + .map(|(s, v)| (s.clone(), v.property_type.clone())) } /// Instantiate a runtime component from this ComponentDescription