@@ -12,26 +12,28 @@ use crate::typeregister::TypeRegister;
12
12
use smol_str:: { format_smolstr, SmolStr , ToSmolStr } ;
13
13
use std:: rc:: Rc ;
14
14
15
- /// If any element in `component` declares a binding to `property_name `, then a new
15
+ /// If any element in `component` declares a binding to any of `property_names `, then a new
16
16
/// element of type `element_name` is created, injected as a parent to the element and bindings
17
- /// to property_name and all properties in extra_properties are mapped.
17
+ /// to all properties in property_names and extra_properties are mapped.
18
18
/// Default value for the property extra_properties is queried with the `default_value_for_extra_properties`
19
19
pub ( crate ) fn lower_property_to_element (
20
20
component : & Rc < Component > ,
21
- property_name : & ' static str ,
21
+ property_names : impl Iterator < Item = & ' static str > + Clone ,
22
22
extra_properties : impl Iterator < Item = & ' static str > + Clone ,
23
23
default_value_for_extra_properties : Option < & dyn Fn ( & ElementRc , & str ) -> Expression > ,
24
24
element_name : & SmolStr ,
25
25
type_register : & TypeRegister ,
26
26
diag : & mut BuildDiagnostics ,
27
27
) {
28
- if let Some ( b) = component. root_element . borrow ( ) . bindings . get ( property_name) {
29
- diag. push_warning (
30
- format ! (
31
- "The {property_name} property cannot be used on the root element, it will not be applied"
32
- ) ,
33
- & * b. borrow ( ) ,
34
- ) ;
28
+ for property_name in property_names. clone ( ) {
29
+ if let Some ( b) = component. root_element . borrow ( ) . bindings . get ( property_name) {
30
+ diag. push_warning (
31
+ format ! (
32
+ "The {property_name} property cannot be used on the root element, it will not be applied"
33
+ ) ,
34
+ & * b. borrow ( ) ,
35
+ ) ;
36
+ }
35
37
}
36
38
37
39
object_tree:: recurse_elem_including_sub_components_no_borrow ( component, & ( ) , & mut |elem, _| {
@@ -46,13 +48,15 @@ pub(crate) fn lower_property_to_element(
46
48
} ;
47
49
48
50
let has_property_binding = |e : & ElementRc | {
49
- e. borrow ( ) . base_type . lookup_property ( property_name) . property_type != Type :: Invalid
50
- && ( e. borrow ( ) . bindings . contains_key ( property_name)
51
- || e. borrow ( )
52
- . property_analysis
53
- . borrow ( )
54
- . get ( property_name)
55
- . is_some_and ( |a| a. is_set || a. is_linked ) )
51
+ property_names. clone ( ) . any ( |property_name| {
52
+ e. borrow ( ) . base_type . lookup_property ( property_name) . property_type != Type :: Invalid
53
+ && ( e. borrow ( ) . bindings . contains_key ( property_name)
54
+ || e. borrow ( )
55
+ . property_analysis
56
+ . borrow ( )
57
+ . get ( property_name)
58
+ . is_some_and ( |a| a. is_set || a. is_linked ) )
59
+ } )
56
60
} ;
57
61
58
62
for mut child in old_children {
@@ -63,8 +67,7 @@ pub(crate) fn lower_property_to_element(
63
67
& child,
64
68
create_property_element (
65
69
& root_elem,
66
- property_name,
67
- extra_properties. clone ( ) ,
70
+ property_names. clone ( ) . chain ( extra_properties. clone ( ) ) ,
68
71
default_value_for_extra_properties,
69
72
element_name,
70
73
type_register,
@@ -74,8 +77,7 @@ pub(crate) fn lower_property_to_element(
74
77
} else if has_property_binding ( & child) {
75
78
let new_child = create_property_element (
76
79
& child,
77
- property_name,
78
- extra_properties. clone ( ) ,
80
+ property_names. clone ( ) . chain ( extra_properties. clone ( ) ) ,
79
81
default_value_for_extra_properties,
80
82
element_name,
81
83
type_register,
@@ -92,14 +94,12 @@ pub(crate) fn lower_property_to_element(
92
94
93
95
fn create_property_element (
94
96
child : & ElementRc ,
95
- property_name : & ' static str ,
96
- extra_properties : impl Iterator < Item = & ' static str > ,
97
+ properties : impl Iterator < Item = & ' static str > ,
97
98
default_value_for_extra_properties : Option < & dyn Fn ( & ElementRc , & str ) -> Expression > ,
98
99
element_name : & SmolStr ,
99
100
type_register : & TypeRegister ,
100
101
) -> ElementRc {
101
- let bindings = core:: iter:: once ( property_name)
102
- . chain ( extra_properties)
102
+ let bindings = properties
103
103
. map ( |property_name| {
104
104
let mut bind =
105
105
BindingExpression :: new_two_way ( NamedReference :: new ( child, property_name. into ( ) ) ) ;
@@ -113,7 +113,7 @@ fn create_property_element(
113
113
. collect ( ) ;
114
114
115
115
let element = Element {
116
- id : format_smolstr ! ( "{}-{}" , child. borrow( ) . id, property_name ) ,
116
+ id : format_smolstr ! ( "{}-{}" , child. borrow( ) . id, element_name ) ,
117
117
base_type : type_register. lookup_element ( element_name) . unwrap ( ) ,
118
118
enclosing_component : child. borrow ( ) . enclosing_component . clone ( ) ,
119
119
bindings,
0 commit comments