Change events: keep unused property with change event

This commit is contained in:
Olivier Goffart 2024-08-15 13:02:40 +02:00
parent 3a12ebf7ab
commit 2643a327e8
2 changed files with 14 additions and 19 deletions

View file

@ -12,26 +12,21 @@ pub fn remove_unused_properties(doc: &Document) {
component,
&(),
&mut |elem, _| {
let mut elem = elem.borrow_mut();
let mut to_remove = HashSet::new();
for (prop, decl) in &elem.borrow().property_declarations {
for (prop, decl) in &elem.property_declarations {
if !decl.expose_in_public_api
&& !elem.borrow().named_references.is_referenced(prop)
&& !elem
.borrow()
.property_analysis
.borrow()
.get(prop)
.map_or(false, |v| v.is_used())
&& !elem.named_references.is_referenced(prop)
&& !elem.property_analysis.borrow().get(prop).map_or(false, |v| v.is_used())
&& !elem.change_callbacks.contains_key(prop)
{
to_remove.insert(prop.to_owned());
}
}
let mut elem = elem.borrow_mut();
for x in &to_remove {
elem.property_declarations.remove(x);
elem.property_analysis.borrow_mut().remove(x);
elem.bindings.remove(x);
elem.change_callbacks.remove(x);
}
},
);

View file

@ -107,19 +107,19 @@ instance.set_value(142);
assert_eq!(instance.get_result(), "");
assert_eq!(instance.get_count(), 0);
slint_testing::mock_elapsed_time(1);
assert_eq!(instance.get_result(), "other(100)value(142)");
assert_eq!(instance.get_result(), "other(100)foo,value(142)");
assert_eq!(instance.get_count(), 1);
instance.set_value(8); // this one is going to be merged in the other
instance.set_value(141);
slint_testing::mock_elapsed_time(1);
assert_eq!(instance.get_result(), "other(100)value(142)value(141)");
assert_eq!(instance.get_result(), "other(100)foo,value(142)value(141)");
assert_eq!(instance.get_count(), 2);
// Changing a value and back doesn't have effect
instance.set_value(85);
instance.set_value(141);
slint_testing::mock_elapsed_time(1);
assert_eq!(instance.get_result(), "other(100)value(142)value(141)");
assert_eq!(instance.get_result(), "other(100)foo,value(142)value(141)");
assert_eq!(instance.get_count(), 2);
instance.set_result("".into());
@ -147,19 +147,19 @@ instance.set_value(142);
assert_eq(instance.get_result(), "");
assert_eq(instance.get_count(), 0);
slint_testing::mock_elapsed_time(1);
assert_eq(instance.get_result(), "other(100)value(142)");
assert_eq(instance.get_result(), "other(100)foo,value(142)");
assert_eq(instance.get_count(), 1);
instance.set_value(8); // this one is going to be merged in the other
instance.set_value(141);
slint_testing::mock_elapsed_time(1);
assert_eq(instance.get_result(), "other(100)value(142)value(141)");
assert_eq(instance.get_result(), "other(100)foo,value(142)value(141)");
assert_eq(instance.get_count(), 2);
// Changing a value and back doesn't have effect
instance.set_value(85);
instance.set_value(141);
slint_testing::mock_elapsed_time(1);
assert_eq(instance.get_result(), "other(100)value(142)value(141)");
assert_eq(instance.get_result(), "other(100)foo,value(142)value(141)");
assert_eq(instance.get_count(), 2);
instance.set_result("");
@ -184,17 +184,17 @@ assert.equal(instance.result, ""); // so far, nothing have changed
instance.value = 142;
assert.equal(instance.result, "");
slintlib.private_api.mock_elapsed_time(1);
assert.equal(instance.result, "other(100)value(142)");
assert.equal(instance.result, "other(100)foo,value(142)");
instance.value = 8; // this one is going to be merged in the other
instance.value = 141;
slintlib.private_api.mock_elapsed_time(1);
assert.equal(instance.result, "other(100)value(142)value(141)");
assert.equal(instance.result, "other(100)foo,value(142)value(141)");
// Changing a value and back doesn't have effect
instance.value = 85;
instance.value = 141;
slintlib.private_api.mock_elapsed_time(1);
assert.equal(instance.result, "other(100)value(142)value(141)");
assert.equal(instance.result, "other(100)foo,value(142)value(141)");
instance.result = "";
instance.chaining_do_change();