From 64365cd3619ef1a165c964cbd768a8dd92ae3485 Mon Sep 17 00:00:00 2001 From: Jonathan Kelley Date: Fri, 2 Feb 2024 16:13:06 -0800 Subject: [PATCH] make sure reactive context works across threads --- packages/signals/src/rc.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/signals/src/rc.rs b/packages/signals/src/rc.rs index 6142c5135..8aeebf852 100644 --- a/packages/signals/src/rc.rs +++ b/packages/signals/src/rc.rs @@ -1,9 +1,9 @@ use dioxus_core::prelude::{ - current_scope_id, has_context, needs_update_any, provide_context, ScopeId, + current_scope_id, has_context, provide_context, schedule_update_any, ScopeId, }; use generational_box::{GenerationalBoxId, SyncStorage}; use rustc_hash::{FxHashMap, FxHashSet}; -use std::{cell::RefCell, hash::Hash}; +use std::{cell::RefCell, hash::Hash, sync::Arc}; use crate::{CopyValue, RcList, Readable, Writable}; @@ -36,6 +36,7 @@ impl ReactiveContext { scope_subscribers, sender: tx, self_: None, + update_any: schedule_update_any(), receiver: rx, }; @@ -86,7 +87,7 @@ impl ReactiveContext { /// If there's a scope associated with this context, then it will be marked as dirty too pub fn mark_dirty(&self) { for scope in self.inner.read().scope_subscribers.iter() { - needs_update_any(*scope); + (self.inner.read().update_any)(*scope); } // mark the listeners as dirty @@ -121,6 +122,7 @@ struct Inner { signal_subscribers: FxHashMap, scope_subscribers: FxHashSet, self_: Option, + update_any: Arc, // Futures will call .changed().await sender: flume::Sender<()>,