mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-06 02:37:21 +00:00
Add ModelContext::observe_global
This commit is contained in:
parent
4d615655aa
commit
0408a8259e
1 changed files with 13 additions and 0 deletions
|
@ -3120,6 +3120,19 @@ impl<'a, T: Entity> ModelContext<'a, T> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn observe_global<G, F>(&mut self, mut callback: F) -> Subscription
|
||||||
|
where
|
||||||
|
G: Any,
|
||||||
|
F: 'static + FnMut(&mut T, &mut ModelContext<T>),
|
||||||
|
{
|
||||||
|
let observer = self.weak_handle();
|
||||||
|
self.app.observe_global::<G, _>(move |cx| {
|
||||||
|
if let Some(observer) = observer.upgrade(cx) {
|
||||||
|
observer.update(cx, |observer, cx| callback(observer, cx));
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
pub fn observe_release<S, F>(
|
pub fn observe_release<S, F>(
|
||||||
&mut self,
|
&mut self,
|
||||||
handle: &ModelHandle<S>,
|
handle: &ModelHandle<S>,
|
||||||
|
|
Loading…
Reference in a new issue