Correct, calling sleep or alert will give control back to the JavaScript event loop. If there is a scheduled tick event it will now fire.
The tick fires
The repeating panel items get replaced.
The component got replaced and is no longer on the screen and has no parent.
Alert/sleep completes and gets control of the event loop
self.parent is now None.
A fun way to work with this might be to use a function as the repeating panel item template.
The function itself can cache components by some sort of id and return a cached component if it exists.
self.repeating_panel.item_template = self.cached_template
def cached_template(self, item):
id = item["id"]
if id in self._cache:
return self._cache[id]
else:
rv = ItemTemplate(item=item)
self._cache[id] = rv
return rv
(Doesn’t handle cache invalidation which you might want to consider)
This can also leads to some interesting patterns
else:
rv = ItemTemplate(item=item, on_delete=self.on_delete)
self._cache[id] = rv
return rv
now you don’t need to raise events on parents since you passed the callback to the child.