Checkpoint

This commit is contained in:
Antonio Scandurra 2023-10-12 13:25:49 +02:00
parent 23f11fcd5e
commit 80c0a6ead3
6 changed files with 23 additions and 24 deletions

View file

@ -148,8 +148,8 @@ impl AppContext {
fn flush_effects(&mut self) { fn flush_effects(&mut self) {
while let Some(effect) = self.pending_effects.pop_front() { while let Some(effect) = self.pending_effects.pop_front() {
match effect { match effect {
Effect::Notify(entity_id) => self.apply_notify_effect(entity_id), Effect::Notify { emitter } => self.apply_notify_effect(emitter),
Effect::Emit { entity_id, event } => self.apply_emit_effect(entity_id, event), Effect::Emit { emitter, event } => self.apply_emit_effect(emitter, event),
} }
} }
@ -171,16 +171,16 @@ impl AppContext {
} }
} }
fn apply_notify_effect(&mut self, updated_entity: EntityId) { fn apply_notify_effect(&mut self, emitter: EntityId) {
self.observers self.observers
.clone() .clone()
.retain(&updated_entity, |handler| handler(self)); .retain(&emitter, |handler| handler(self));
} }
fn apply_emit_effect(&mut self, updated_entity: EntityId, event: Box<dyn Any>) { fn apply_emit_effect(&mut self, emitter: EntityId, event: Box<dyn Any>) {
self.event_handlers self.event_handlers
.clone() .clone()
.retain(&updated_entity, |handler| handler(&event, self)); .retain(&emitter, |handler| handler(&event, self));
} }
pub fn to_async(&self) -> AsyncAppContext { pub fn to_async(&self) -> AsyncAppContext {
@ -380,9 +380,11 @@ impl MainThread<AppContext> {
} }
pub(crate) enum Effect { pub(crate) enum Effect {
Notify(EntityId), Notify {
emitter: EntityId,
},
Emit { Emit {
entity_id: EntityId, emitter: EntityId,
event: Box<dyn Any + Send + Sync + 'static>, event: Box<dyn Any + Send + Sync + 'static>,
}, },
} }

View file

@ -86,16 +86,16 @@ impl<'a, T: Send + Sync + 'static> ModelContext<'a, T> {
} }
pub fn notify(&mut self) { pub fn notify(&mut self) {
self.app self.app.pending_effects.push_back(Effect::Notify {
.pending_effects emitter: self.entity_id,
.push_back(Effect::Notify(self.entity_id)); });
} }
} }
impl<'a, T: EventEmitter + Send + Sync + 'static> ModelContext<'a, T> { impl<'a, T: EventEmitter + Send + Sync + 'static> ModelContext<'a, T> {
pub fn emit(&mut self, event: T::Event) { pub fn emit(&mut self, event: T::Event) {
self.app.pending_effects.push_back(Effect::Emit { self.app.pending_effects.push_back(Effect::Emit {
entity_id: self.entity_id, emitter: self.entity_id,
event: Box::new(event), event: Box::new(event),
}); });
} }

View file

@ -966,7 +966,9 @@ impl<'a, 'w, S: Send + Sync + 'static> ViewContext<'a, 'w, S> {
self.window_cx self.window_cx
.app .app
.pending_effects .pending_effects
.push_back(Effect::Notify(self.entity_id)); .push_back(Effect::Notify {
emitter: self.entity_id,
});
} }
pub fn run_on_main<R>( pub fn run_on_main<R>(
@ -1016,9 +1018,8 @@ impl<'a, 'w, S: Send + Sync + 'static> ViewContext<'a, 'w, S> {
impl<'a, 'w, S: EventEmitter + Send + Sync + 'static> ViewContext<'a, 'w, S> { impl<'a, 'w, S: EventEmitter + Send + Sync + 'static> ViewContext<'a, 'w, S> {
pub fn emit(&mut self, event: S::Event) { pub fn emit(&mut self, event: S::Event) {
let entity_id = self.entity_id; self.window_cx.app.pending_effects.push_back(Effect::Emit {
self.app.pending_effects.push_back(Effect::Emit { emitter: self.entity_id,
entity_id,
event: Box::new(event), event: Box::new(event),
}); });
} }

View file

@ -1,8 +1,7 @@
use crate::theme::{theme, Theme}; use crate::theme::{theme, Theme};
use gpui3::{ use gpui3::{
div, img, svg, view, AppContext, Context, Element, ElementId, IdentifiedElement, div, svg, view, AppContext, Context, Element, ElementId, IntoAnyElement, ParentElement,
IntoAnyElement, ParentElement, ScrollState, SharedString, StyleHelpers, Styled, View, ScrollState, SharedString, StyleHelpers, Styled, View, ViewContext, WindowContext,
ViewContext, WindowContext,
}; };
pub struct CollabPanel { pub struct CollabPanel {

View file

@ -1,13 +1,10 @@
#![allow(dead_code, unused_variables)] #![allow(dead_code, unused_variables)]
use assets::Assets; use assets::Assets;
use gpui3::{ use gpui3::{px, size, Bounds, WindowBounds, WindowOptions};
div, px, size, Bounds, Element, StyleHelpers, WindowBounds, WindowContext, WindowOptions,
};
use log::LevelFilter; use log::LevelFilter;
use simplelog::SimpleLogger; use simplelog::SimpleLogger;
use std::sync::Arc; use std::sync::Arc;
use themes::rose_pine;
use workspace::workspace; use workspace::workspace;
mod assets; mod assets;

View file

@ -1,7 +1,7 @@
use crate::{ use crate::{
collab_panel::{collab_panel, CollabPanel}, collab_panel::{collab_panel, CollabPanel},
theme::{theme, themed}, theme::{theme, themed},
themes::{rose_pine, rose_pine_dawn}, themes::rose_pine,
}; };
use gpui3::{ use gpui3::{
div, img, svg, view, Context, Element, ParentElement, RootView, StyleHelpers, Styled, View, div, img, svg, view, Context, Element, ParentElement, RootView, StyleHelpers, Styled, View,