Remove model and view specific observe/subscribe methods

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Max Brunsfeld
2021-08-23 15:07:50 -07:00
co-authored by Nathan Sobo
parent 5ecedd894d
commit fa0739ee2e
5 changed files with 24 additions and 58 deletions
+3 -3
View File
@@ -324,9 +324,9 @@ impl Editor {
) -> Self {
let display_map =
cx.add_model(|cx| DisplayMap::new(buffer.clone(), settings.borrow().clone(), None, cx));
cx.observe_model(&buffer, Self::on_buffer_changed);
cx.subscribe_to_model(&buffer, Self::on_buffer_event);
cx.observe_model(&display_map, Self::on_display_map_changed);
cx.observe(&buffer, Self::on_buffer_changed);
cx.subscribe(&buffer, Self::on_buffer_event);
cx.observe(&display_map, Self::on_display_map_changed);
let mut next_selection_id = 0;
let selection_set_id = buffer.update(cx, |buffer, cx| {
+3 -3
View File
@@ -252,7 +252,7 @@ impl FileFinder {
workspace.toggle_modal(cx, |cx, workspace| {
let handle = cx.handle();
let finder = cx.add_view(|cx| Self::new(workspace.settings.clone(), handle, cx));
cx.subscribe_to_view(&finder, Self::on_event);
cx.subscribe(&finder, Self::on_event);
finder
});
}
@@ -281,10 +281,10 @@ impl FileFinder {
workspace: ViewHandle<Workspace>,
cx: &mut ViewContext<Self>,
) -> Self {
cx.observe_view(&workspace, Self::workspace_updated);
cx.observe(&workspace, Self::workspace_updated);
let query_buffer = cx.add_view(|cx| Editor::single_line(settings.clone(), cx));
cx.subscribe_to_view(&query_buffer, Self::on_query_editor_event);
cx.subscribe(&query_buffer, Self::on_query_editor_event);
Self {
handle: cx.handle().downgrade(),
+2 -2
View File
@@ -61,7 +61,7 @@ impl ThemeSelector {
cx: &mut ViewContext<Self>,
) -> Self {
let query_buffer = cx.add_view(|cx| Editor::single_line(settings.clone(), cx));
cx.subscribe_to_view(&query_buffer, Self::on_query_editor_event);
cx.subscribe(&query_buffer, Self::on_query_editor_event);
let mut this = Self {
settings,
@@ -86,7 +86,7 @@ impl ThemeSelector {
cx,
)
});
cx.subscribe_to_view(&selector, Self::on_event);
cx.subscribe(&selector, Self::on_event);
selector
});
}
+5 -5
View File
@@ -279,7 +279,7 @@ impl<T: ItemView> ItemViewHandle for ViewHandle<T> {
fn set_parent_pane(&self, pane: &ViewHandle<Pane>, cx: &mut MutableAppContext) {
pane.update(cx, |_, cx| {
cx.subscribe_to_view(self, |pane, item, event, cx| {
cx.subscribe(self, |pane, item, event, cx| {
if T::should_activate_item_on_event(event) {
if let Some(ix) = pane.item_index(&item) {
pane.activate_item(ix, cx);
@@ -358,7 +358,7 @@ impl Workspace {
pub fn new(app_state: &AppState, cx: &mut ViewContext<Self>) -> Self {
let pane = cx.add_view(|_| Pane::new(app_state.settings.clone()));
let pane_id = pane.id();
cx.subscribe_to_view(&pane, move |me, _, event, cx| {
cx.subscribe(&pane, move |me, _, event, cx| {
me.handle_pane_event(pane_id, event, cx)
});
cx.focus(&pane);
@@ -526,7 +526,7 @@ impl Workspace {
cx.spawn(|this, mut cx| async move {
let worktree = Worktree::open_local(path, languages, fs, &mut cx).await?;
this.update(&mut cx, |this, cx| {
cx.observe_model(&worktree, |_, _, cx| cx.notify());
cx.observe(&worktree, |_, _, cx| cx.notify());
this.worktrees.insert(worktree.clone());
cx.notify();
});
@@ -835,7 +835,7 @@ impl Workspace {
Worktree::open_remote(rpc.clone(), worktree_id, access_token, languages, &mut cx)
.await?;
this.update(&mut cx, |workspace, cx| {
cx.observe_model(&worktree, |_, _, cx| cx.notify());
cx.observe(&worktree, |_, _, cx| cx.notify());
workspace.worktrees.insert(worktree);
cx.notify();
});
@@ -854,7 +854,7 @@ impl Workspace {
fn add_pane(&mut self, cx: &mut ViewContext<Self>) -> ViewHandle<Pane> {
let pane = cx.add_view(|_| Pane::new(self.settings.clone()));
let pane_id = pane.id();
cx.subscribe_to_view(&pane, move |me, _, event, cx| {
cx.subscribe(&pane, move |me, _, event, cx| {
me.handle_pane_event(pane_id, event, cx)
});
self.panes.push(pane.clone());