Allow direct read/update of WeakViewHandle
only in AsyncAppContext
This commit is contained in:
parent
2b6830c798
commit
57beec6071
3 changed files with 13 additions and 12 deletions
|
@ -4086,10 +4086,10 @@ impl<V: View> WeakViewHandle<V> {
|
||||||
|
|
||||||
pub fn read_with<T>(
|
pub fn read_with<T>(
|
||||||
&self,
|
&self,
|
||||||
cx: &impl BorrowAppContext,
|
cx: &AsyncAppContext,
|
||||||
read: impl FnOnce(&V, &ViewContext<V>) -> T,
|
read: impl FnOnce(&V, &ViewContext<V>) -> T,
|
||||||
) -> Result<T> {
|
) -> Result<T> {
|
||||||
cx.read_with(|cx| {
|
cx.read(|cx| {
|
||||||
let handle = cx
|
let handle = cx
|
||||||
.upgrade_view_handle(self)
|
.upgrade_view_handle(self)
|
||||||
.ok_or_else(|| anyhow!("view {} was dropped", V::ui_name()))?;
|
.ok_or_else(|| anyhow!("view {} was dropped", V::ui_name()))?;
|
||||||
|
@ -4100,7 +4100,7 @@ impl<V: View> WeakViewHandle<V> {
|
||||||
|
|
||||||
pub fn update<T>(
|
pub fn update<T>(
|
||||||
&self,
|
&self,
|
||||||
cx: &mut impl BorrowAppContext,
|
cx: &mut AsyncAppContext,
|
||||||
update: impl FnOnce(&mut V, &mut ViewContext<V>) -> T,
|
update: impl FnOnce(&mut V, &mut ViewContext<V>) -> T,
|
||||||
) -> Result<T> {
|
) -> Result<T> {
|
||||||
cx.update(|cx| {
|
cx.update(|cx| {
|
||||||
|
|
|
@ -201,10 +201,11 @@ impl ToolbarItemView for BufferSearchBar {
|
||||||
Some(searchable_item_handle.subscribe_to_search_events(
|
Some(searchable_item_handle.subscribe_to_search_events(
|
||||||
cx,
|
cx,
|
||||||
Box::new(move |search_event, cx| {
|
Box::new(move |search_event, cx| {
|
||||||
|
if let Some(this) = this.upgrade(cx) {
|
||||||
this.update(cx, |this, cx| {
|
this.update(cx, |this, cx| {
|
||||||
this.on_active_searchable_item_event(search_event, cx)
|
this.on_active_searchable_item_event(search_event, cx)
|
||||||
})
|
});
|
||||||
.log_err();
|
}
|
||||||
}),
|
}),
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
|
@ -2005,12 +2005,12 @@ impl NavHistory {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn did_update(&self, cx: &mut WindowContext) {
|
fn did_update(&self, cx: &mut WindowContext) {
|
||||||
let pane = self.pane.clone();
|
if let Some(pane) = self.pane.upgrade(cx) {
|
||||||
cx.defer(move |cx| {
|
cx.defer(move |cx| {
|
||||||
pane.update(cx, |pane, cx| pane.history_updated(cx))
|
pane.update(cx, |pane, cx| pane.history_updated(cx));
|
||||||
.log_err();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct PaneBackdrop<V: View> {
|
pub struct PaneBackdrop<V: View> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue