Use a WeakViewHandle
in Client
for view message handlers
This commit is contained in:
parent
57beec6071
commit
689e878bd8
3 changed files with 32 additions and 19 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue