gpui: notifications now takes an entity instead of a model

This commit is contained in:
Piotr Osiewicz
2023-11-17 17:23:05 +01:00
parent ae1ebc6858
commit eb9959a0cf
+9 -10
View File
@@ -1,8 +1,9 @@
use crate::{
div, Action, AnyView, AnyWindowHandle, AppCell, AppContext, AsyncAppContext,
BackgroundExecutor, Context, Div, EventEmitter, ForegroundExecutor, InputEvent, KeyDownEvent,
Keystroke, Model, ModelContext, Render, Result, Task, TestDispatcher, TestPlatform, TestWindow,
View, ViewContext, VisualContext, WindowContext, WindowHandle, WindowOptions,
BackgroundExecutor, Context, Div, Entity, EventEmitter, ForegroundExecutor, InputEvent,
KeyDownEvent, Keystroke, Model, ModelContext, Render, Result, Task, TestDispatcher,
TestPlatform, TestWindow, View, ViewContext, VisualContext, WindowContext, WindowHandle,
WindowOptions,
};
use anyhow::{anyhow, bail};
use futures::{Stream, StreamExt};
@@ -296,21 +297,19 @@ impl TestAppContext {
.unwrap()
}
pub fn notifications<T: 'static>(&mut self, entity: &Model<T>) -> impl Stream<Item = ()> {
pub fn notifications<T: 'static>(&mut self, entity: &impl Entity<T>) -> impl Stream<Item = ()> {
let (tx, rx) = futures::channel::mpsc::unbounded();
entity.update(self, move |_, cx: &mut ModelContext<T>| {
self.update(|cx| {
cx.observe(entity, {
let tx = tx.clone();
move |_, _, _| {
move |_, _| {
let _ = tx.unbounded_send(());
}
})
.detach();
cx.on_release(move |_, _| tx.close_channel()).detach();
cx.observe_release(entity, move |_, _| tx.close_channel())
.detach()
});
rx
}