diff --git a/packages/core/src/scope_context.rs b/packages/core/src/scope_context.rs index fec34f914..0861d063f 100644 --- a/packages/core/src/scope_context.rs +++ b/packages/core/src/scope_context.rs @@ -5,7 +5,7 @@ use crate::{ }; use rustc_hash::FxHashSet; use std::{ - any::{Any, TypeId}, + any::Any, cell::{Cell, RefCell}, fmt::Debug, future::Future, @@ -25,7 +25,7 @@ pub struct ScopeContext { pub(crate) height: u32, pub(crate) suspended: Cell, - pub(crate) shared_contexts: RefCell)>>, + pub(crate) shared_contexts: RefCell>>, pub(crate) tasks: Rc, pub(crate) spawned_tasks: RefCell>, @@ -99,9 +99,7 @@ impl ScopeContext { self.shared_contexts .borrow() .iter() - .find(|(k, _)| *k == TypeId::of::()) - .map(|(_, v)| v)? - .downcast_ref::() + .find_map(|any| any.downcast_ref::()) .cloned() } @@ -121,7 +119,7 @@ impl ScopeContext { .shared_contexts .borrow() .iter() - .find_map(|(_, any)| any.downcast_ref::()) + .find_map(|any| any.downcast_ref::()) { return Some(shared.clone()); } @@ -159,14 +157,14 @@ impl ScopeContext { // If the context exists, swap it out for the new value for ctx in contexts.iter_mut() { // Swap the ptr directly - if let Some(ctx) = ctx.1.downcast_mut::() { + if let Some(ctx) = ctx.downcast_mut::() { std::mem::swap(ctx, &mut value.clone()); return value; } } // Else, just push it - contexts.push((TypeId::of::(), Box::new(value.clone()))); + contexts.push(Box::new(value.clone())); value } diff --git a/packages/signals/src/effect.rs b/packages/signals/src/effect.rs index fdceb5211..0685938a0 100644 --- a/packages/signals/src/effect.rs +++ b/packages/signals/src/effect.rs @@ -1,16 +1,16 @@ use core::{self, fmt::Debug}; +use std::cell::RefCell; use std::fmt::{self, Formatter}; -use std::marker::PhantomData; - +use std::rc::Rc; +// use dioxus_core::prelude::*; -use crate::dependency::Dep; +use crate::use_signal; use crate::{dependency::Dependency, CopyValue}; -use crate::{use_signal, Signal}; -#[derive(Default, Clone, Copy)] +#[derive(Default, Clone)] pub(crate) struct EffectStack { - pub(crate) effects: CopyValue>, + pub(crate) effects: Rc>>, } pub(crate) fn get_effect_stack() -> EffectStack { @@ -65,7 +65,7 @@ impl Debug for Effect { impl Effect { pub(crate) fn current() -> Option { - get_effect_stack().effects.read().last().copied() + get_effect_stack().effects.borrow().last().copied() } /// Create a new effect. The effect will be run immediately and whenever any signal it reads changes. @@ -85,11 +85,11 @@ impl Effect { pub fn try_run(&self) { if let Some(mut callback) = self.callback.try_write() { { - get_effect_stack().effects.write().push(*self); + get_effect_stack().effects.borrow_mut().push(*self); } callback(); { - get_effect_stack().effects.write().pop(); + get_effect_stack().effects.borrow_mut().pop(); } } } diff --git a/packages/signals/src/rt.rs b/packages/signals/src/rt.rs index 685a77204..0f0b3a8c2 100644 --- a/packages/signals/src/rt.rs +++ b/packages/signals/src/rt.rs @@ -3,8 +3,8 @@ use std::cell::{Ref, RefMut}; use std::rc::Rc; use dioxus_core::prelude::{ - consume_context, consume_context_from_scope, current_scope_id, provide_context_to_scope, - provide_root_context, + consume_context, consume_context_from_scope, current_scope_id, provide_context, + provide_context_to_scope, provide_root_context, }; use dioxus_core::ScopeId; @@ -25,7 +25,7 @@ fn current_owner() -> Rc { Some(rt) => rt, None => { let owner = Rc::new(current_store().owner()); - provide_root_context(owner).expect("in a virtual dom") + provide_context(owner).expect("in a virtual dom") } } } diff --git a/packages/signals/src/selector.rs b/packages/signals/src/selector.rs index 81fb50398..301f4495e 100644 --- a/packages/signals/src/selector.rs +++ b/packages/signals/src/selector.rs @@ -78,7 +78,7 @@ pub fn selector(mut f: impl FnMut() -> R + 'static) -> ReadOnlySig }; { - get_effect_stack().effects.write().push(effect); + get_effect_stack().effects.borrow_mut().push(effect); } state.inner.value.set(SignalData { subscribers: Default::default(), @@ -87,7 +87,7 @@ pub fn selector(mut f: impl FnMut() -> R + 'static) -> ReadOnlySig value: f(), }); { - get_effect_stack().effects.write().pop(); + // get_effect_stack().effects.borrow_mut().pop(); } effect.callback.value.set(Box::new(move || {