WIP
This commit is contained in:
parent
38ab6b123f
commit
493a418c91
5 changed files with 19 additions and 6 deletions
|
@ -173,11 +173,13 @@ pub trait ReadViewWith {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait UpdateView {
|
pub trait UpdateView {
|
||||||
|
type Output<S>;
|
||||||
|
|
||||||
fn update_view<T, S>(
|
fn update_view<T, S>(
|
||||||
&mut self,
|
&mut self,
|
||||||
handle: &ViewHandle<T>,
|
handle: &ViewHandle<T>,
|
||||||
update: &mut dyn FnMut(&mut T, &mut ViewContext<T>) -> S,
|
update: &mut dyn FnMut(&mut T, &mut ViewContext<T>) -> S,
|
||||||
) -> S
|
) -> Self::Output<S>
|
||||||
where
|
where
|
||||||
T: View;
|
T: View;
|
||||||
}
|
}
|
||||||
|
@ -462,18 +464,19 @@ impl ReadModelWith for AsyncAppContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UpdateView for AsyncAppContext {
|
impl UpdateView for AsyncAppContext {
|
||||||
|
type Output<S> = Option<S>;
|
||||||
|
|
||||||
fn update_view<T, S>(
|
fn update_view<T, S>(
|
||||||
&mut self,
|
&mut self,
|
||||||
handle: &ViewHandle<T>,
|
handle: &ViewHandle<T>,
|
||||||
update: &mut dyn FnMut(&mut T, &mut ViewContext<T>) -> S,
|
update: &mut dyn FnMut(&mut T, &mut ViewContext<T>) -> S,
|
||||||
) -> S
|
) -> Option<S>
|
||||||
where
|
where
|
||||||
T: View,
|
T: View,
|
||||||
{
|
{
|
||||||
self.0
|
self.0
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.update_window(handle.window_id, |cx| cx.update_view(handle, update))
|
.update_window(handle.window_id, |cx| cx.update_view(handle, update))
|
||||||
.unwrap() // TODO: is this unwrap safe?
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3472,6 +3475,8 @@ impl<V: View> ReadView for ViewContext<'_, '_, '_, V> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<V: View> UpdateView for ViewContext<'_, '_, '_, V> {
|
impl<V: View> UpdateView for ViewContext<'_, '_, '_, V> {
|
||||||
|
type Output<S> = S;
|
||||||
|
|
||||||
fn update_view<T, S>(
|
fn update_view<T, S>(
|
||||||
&mut self,
|
&mut self,
|
||||||
handle: &ViewHandle<T>,
|
handle: &ViewHandle<T>,
|
||||||
|
@ -3533,6 +3538,8 @@ impl<V: View> ReadView for EventContext<'_, '_, '_, '_, V> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<V: View> UpdateView for EventContext<'_, '_, '_, '_, V> {
|
impl<V: View> UpdateView for EventContext<'_, '_, '_, '_, V> {
|
||||||
|
type Output<S> = S;
|
||||||
|
|
||||||
fn update_view<T, S>(
|
fn update_view<T, S>(
|
||||||
&mut self,
|
&mut self,
|
||||||
handle: &ViewHandle<T>,
|
handle: &ViewHandle<T>,
|
||||||
|
@ -3913,7 +3920,7 @@ impl<T: View> ViewHandle<T> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update<C, F, S>(&self, cx: &mut C, update: F) -> S
|
pub fn update<C, F, S>(&self, cx: &mut C, update: F) -> C::Output<S>
|
||||||
where
|
where
|
||||||
C: UpdateView,
|
C: UpdateView,
|
||||||
F: FnOnce(&mut T, &mut ViewContext<T>) -> S,
|
F: FnOnce(&mut T, &mut ViewContext<T>) -> S,
|
||||||
|
|
|
@ -404,6 +404,8 @@ impl ReadModelWith for TestAppContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UpdateView for TestAppContext {
|
impl UpdateView for TestAppContext {
|
||||||
|
type Output<S> = S;
|
||||||
|
|
||||||
fn update_view<T, S>(
|
fn update_view<T, S>(
|
||||||
&mut self,
|
&mut self,
|
||||||
handle: &ViewHandle<T>,
|
handle: &ViewHandle<T>,
|
||||||
|
|
|
@ -155,6 +155,8 @@ impl ReadView for WindowContext<'_, '_> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UpdateView for WindowContext<'_, '_> {
|
impl UpdateView for WindowContext<'_, '_> {
|
||||||
|
type Output<S> = S;
|
||||||
|
|
||||||
fn update_view<T, S>(
|
fn update_view<T, S>(
|
||||||
&mut self,
|
&mut self,
|
||||||
handle: &ViewHandle<T>,
|
handle: &ViewHandle<T>,
|
||||||
|
@ -172,7 +174,7 @@ impl UpdateView for WindowContext<'_, '_> {
|
||||||
&mut cx,
|
&mut cx,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.unwrap() // TODO: Is this unwrap safe?
|
.unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -823,6 +823,8 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> UpdateView for DockTestContext<'a> {
|
impl<'a> UpdateView for DockTestContext<'a> {
|
||||||
|
type Output<S> = S;
|
||||||
|
|
||||||
fn update_view<T, S>(
|
fn update_view<T, S>(
|
||||||
&mut self,
|
&mut self,
|
||||||
handle: &ViewHandle<T>,
|
handle: &ViewHandle<T>,
|
||||||
|
|
|
@ -467,7 +467,7 @@ impl<T: Item> ItemHandle for ViewHandle<T> {
|
||||||
workspace.project().clone(),
|
workspace.project().clone(),
|
||||||
cx,
|
cx,
|
||||||
)
|
)
|
||||||
})
|
})?
|
||||||
.await
|
.await
|
||||||
.log_err()?;
|
.log_err()?;
|
||||||
Some(())
|
Some(())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue