Use a WeakViewHandle in Client for view message handlers

This commit is contained in:
Antonio Scandurra 2023-04-26 12:08:15 +02:00
parent 57beec6071
commit 689e878bd8
3 changed files with 32 additions and 19 deletions

View file

@ -4156,9 +4156,24 @@ impl AnyWeakViewHandle {
self.view_id
}
fn is<T: 'static>(&self) -> bool {
TypeId::of::<T>() == self.view_type
}
pub fn upgrade(&self, cx: &impl BorrowAppContext) -> Option<AnyViewHandle> {
cx.read_with(|cx| cx.upgrade_any_view_handle(self))
}
pub fn downcast<T: View>(self) -> Option<WeakViewHandle<T>> {
if self.is::<T>() {
Some(WeakViewHandle {
any_handle: self,
view_type: PhantomData,
})
} else {
None
}
}
}
impl Hash for AnyWeakViewHandle {