@@ -154,29 +154,38 @@ def _render_element(self, element_state: ElementState) -> Dict[str, Any]:
154
154
return element_state .model
155
155
156
156
def _render_model (
157
- self , element_state : ElementState , model : Mapping [str , Any ]
157
+ self ,
158
+ element_state : ElementState ,
159
+ model : Mapping [str , Any ],
160
+ path : str = "" ,
158
161
) -> Dict [str , Any ]:
159
162
serialized_model : Dict [str , Any ] = {}
160
163
event_handlers = self ._render_model_event_targets (element_state , model )
161
164
if event_handlers :
162
165
serialized_model ["eventHandlers" ] = event_handlers
163
166
if "children" in model :
164
167
serialized_model ["children" ] = self ._render_model_children (
165
- element_state , model ["children" ]
168
+ element_state , model ["children" ], path
166
169
)
167
170
return {** model , ** serialized_model }
168
171
169
172
def _render_model_children (
170
- self , element_state : ElementState , children : Union [List [Any ], Tuple [Any , ...]]
173
+ self ,
174
+ element_state : ElementState ,
175
+ children : Union [List [Any ], Tuple [Any , ...]],
176
+ path : str ,
171
177
) -> List [Any ]:
172
178
resolved_children : List [Any ] = []
173
179
for index , child in enumerate (
174
180
children if isinstance (children , (list , tuple )) else [children ]
175
181
):
176
182
if isinstance (child , dict ):
177
- resolved_children .append (self ._render_model (element_state , child ))
183
+ child_path = f"{ path } /children/{ index } "
184
+ resolved_children .append (
185
+ self ._render_model (element_state , child , child_path )
186
+ )
178
187
elif isinstance (child , AbstractElement ):
179
- child_path = f"{ element_state . path } /children/{ index } "
188
+ child_path = f"{ path } /children/{ index } "
180
189
child_state = self ._create_element_state (child , child_path , save = True )
181
190
resolved_children .append (self ._render_element (child_state ))
182
191
element_state .child_elements_ids .append (id (child ))
0 commit comments