Checkpoint
This commit is contained in:
parent
a9c69bf774
commit
a69dbafe3c
4 changed files with 13 additions and 8 deletions
|
@ -88,8 +88,8 @@ impl App {
|
|||
}
|
||||
}
|
||||
|
||||
type Handler = Arc<dyn Fn(&mut AppContext) -> bool + Send + Sync + 'static>;
|
||||
type EventHandler = Arc<dyn Fn(&dyn Any, &mut AppContext) -> bool + Send + Sync + 'static>;
|
||||
type Handler = Box<dyn Fn(&mut AppContext) -> bool + Send + Sync + 'static>;
|
||||
type EventHandler = Box<dyn Fn(&dyn Any, &mut AppContext) -> bool + Send + Sync + 'static>;
|
||||
type FrameCallback = Box<dyn FnOnce(&mut WindowContext) + Send>;
|
||||
|
||||
pub struct AppContext {
|
||||
|
|
|
@ -2,7 +2,7 @@ use crate::{
|
|||
AppContext, Context, Effect, EntityId, EventEmitter, Handle, Reference, Subscription,
|
||||
WeakHandle,
|
||||
};
|
||||
use std::{marker::PhantomData, sync::Arc};
|
||||
use std::marker::PhantomData;
|
||||
|
||||
pub struct ModelContext<'a, T> {
|
||||
app: Reference<'a, AppContext>,
|
||||
|
@ -50,7 +50,7 @@ impl<'a, T: Send + Sync + 'static> ModelContext<'a, T> {
|
|||
let handle = handle.downgrade();
|
||||
self.app.observers.insert(
|
||||
handle.id,
|
||||
Arc::new(move |cx| {
|
||||
Box::new(move |cx| {
|
||||
if let Some((this, handle)) = this.upgrade(cx).zip(handle.upgrade(cx)) {
|
||||
this.update(cx, |this, cx| on_notify(this, handle, cx));
|
||||
true
|
||||
|
@ -73,7 +73,7 @@ impl<'a, T: Send + Sync + 'static> ModelContext<'a, T> {
|
|||
let handle = handle.downgrade();
|
||||
self.app.event_handlers.insert(
|
||||
handle.id,
|
||||
Arc::new(move |event, cx| {
|
||||
Box::new(move |event, cx| {
|
||||
let event = event.downcast_ref().expect("invalid event type");
|
||||
if let Some((this, handle)) = this.upgrade(cx).zip(handle.upgrade(cx)) {
|
||||
this.update(cx, |this, cx| on_event(this, handle, event, cx));
|
||||
|
|
|
@ -3,11 +3,16 @@ use parking_lot::Mutex;
|
|||
use std::{fmt::Debug, mem, sync::Arc};
|
||||
use util::post_inc;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct SubscriberSet<EmitterKey, Callback>(
|
||||
Arc<Mutex<SubscriberSetState<EmitterKey, Callback>>>,
|
||||
);
|
||||
|
||||
impl<EmitterKey, Callback> Clone for SubscriberSet<EmitterKey, Callback> {
|
||||
fn clone(&self) -> Self {
|
||||
SubscriberSet(self.0.clone())
|
||||
}
|
||||
}
|
||||
|
||||
struct SubscriberSetState<EmitterKey, Callback> {
|
||||
subscribers: BTreeMap<EmitterKey, BTreeMap<usize, Callback>>,
|
||||
dropped_subscribers: BTreeSet<(EmitterKey, usize)>,
|
||||
|
|
|
@ -909,7 +909,7 @@ impl<'a, 'w, S: Send + Sync + 'static> ViewContext<'a, 'w, S> {
|
|||
let window_handle = self.window.handle;
|
||||
self.app.observers.insert(
|
||||
handle.id,
|
||||
Arc::new(move |cx| {
|
||||
Box::new(move |cx| {
|
||||
cx.update_window(window_handle.id, |cx| {
|
||||
if let Some(handle) = handle.upgrade(cx) {
|
||||
this.update(cx, |this, cx| on_notify(this, handle, cx))
|
||||
|
@ -936,7 +936,7 @@ impl<'a, 'w, S: Send + Sync + 'static> ViewContext<'a, 'w, S> {
|
|||
let window_handle = self.window.handle;
|
||||
self.app.event_handlers.insert(
|
||||
handle.id,
|
||||
Arc::new(move |event, cx| {
|
||||
Box::new(move |event, cx| {
|
||||
cx.update_window(window_handle.id, |cx| {
|
||||
if let Some(handle) = handle.upgrade(cx) {
|
||||
let event = event.downcast_ref().expect("invalid event type");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue