move ScopeId methods to the runtime (#4723)
* move `ScopeId` methods to runtime methods * cargo check unused * wip... * wip... * fix consume context * fix test * guard hoisted * fix doc comment
This commit is contained in:
1 parent
c56bac04f4
commit
c29cef4ea3
40 files changed
+466
-697
No files matched your search
@@ -1,8 +1,8 @@
|
||||
#![allow(clippy::unnecessary_operation)]
|
||||
#![allow(clippy::no_effect)]
|
||||
|
||||
use dioxus_core::Subscribers;
|
||||
use dioxus_core::{current_owner, current_scope_id, ScopeId};
|
||||
use dioxus_core::{Runtime, Subscribers};
|
||||
use generational_box::{
|
||||
AnyStorage, BorrowResult, GenerationalBox, GenerationalBoxId, Storage, UnsyncStorage,
|
||||
};
|
||||
@@ -82,7 +82,7 @@ impl<T, S: Storage<T>> CopyValue<T, S> {
|
||||
{
|
||||
Self {
|
||||
value: GenerationalBox::leak(value, caller),
|
||||
origin_scope: current_scope_id().expect("in a virtual dom"),
|
||||
origin_scope: current_scope_id(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ impl<T, S: Storage<T>> CopyValue<T, S> {
|
||||
|
||||
Self {
|
||||
value: owner.insert_rc_with_caller(value, caller),
|
||||
origin_scope: current_scope_id().expect("in a virtual dom"),
|
||||
origin_scope: current_scope_id(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,8 +116,7 @@ impl<T, S: Storage<T>> CopyValue<T, S> {
|
||||
scope: ScopeId,
|
||||
caller: &'static std::panic::Location<'static>,
|
||||
) -> Self {
|
||||
let owner = scope.owner();
|
||||
|
||||
let owner = Runtime::current().scope_owner(scope);
|
||||
Self {
|
||||
value: owner.insert_rc_with_caller(value, caller),
|
||||
origin_scope: scope,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use dioxus_core::{ScopeId, Subscribers};
|
||||
use dioxus_core::{Runtime, ScopeId, Subscribers};
|
||||
use generational_box::BorrowResult;
|
||||
use std::{any::Any, cell::RefCell, collections::HashMap, ops::Deref, panic::Location, rc::Rc};
|
||||
|
||||
@@ -190,7 +190,9 @@ where
|
||||
}
|
||||
// Otherwise, create it
|
||||
// Constructors are always run in the root scope
|
||||
let signal = ScopeId::ROOT.in_runtime(|| T::initialize_from_function(self.constructor));
|
||||
let signal = dioxus_core::Runtime::current().in_scope(ScopeId::ROOT, || {
|
||||
T::initialize_from_function(self.constructor)
|
||||
});
|
||||
context
|
||||
.map
|
||||
.borrow_mut()
|
||||
@@ -274,9 +276,10 @@ impl GlobalLazyContext {
|
||||
|
||||
/// Get the global context for signals
|
||||
pub fn get_global_context() -> GlobalLazyContext {
|
||||
match ScopeId::ROOT.has_context() {
|
||||
let rt = Runtime::current();
|
||||
match rt.has_context(ScopeId::ROOT) {
|
||||
Some(context) => context,
|
||||
None => ScopeId::ROOT.provide_context(Default::default()),
|
||||
None => rt.provide_context(ScopeId::ROOT, Default::default()),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -56,8 +56,7 @@ impl<T> Memo<T> {
|
||||
let _ = tx.unbounded_send(());
|
||||
}
|
||||
};
|
||||
let rc =
|
||||
ReactiveContext::new_with_callback(callback, current_scope_id().unwrap(), location);
|
||||
let rc = ReactiveContext::new_with_callback(callback, current_scope_id(), location);
|
||||
|
||||
// Create a new signal in that context, wiring up its dependencies and subscribers
|
||||
let mut recompute = move || rc.reset_and_run_in(&mut f);
|
||||
|
||||
@@ -9,9 +9,13 @@ pub fn copy_value_hoisted<T: 'static, S: generational_box::Storage<T> + 'static>
|
||||
caller: &'static std::panic::Location<'static>,
|
||||
) {
|
||||
let origin_scope = value.origin_scope;
|
||||
if let Ok(current_scope) = dioxus_core::current_scope_id() {
|
||||
let Some(rt) = dioxus_core::Runtime::try_current() else {
|
||||
return;
|
||||
};
|
||||
|
||||
if let Some(current_scope) = rt.try_current_scope_id() {
|
||||
// If the current scope is a descendant of the origin scope or is the same scope, we don't need to warn
|
||||
if origin_scope == current_scope || current_scope.is_descendant_of(origin_scope) {
|
||||
if origin_scope == current_scope || rt.is_descendant_of(current_scope, origin_scope) {
|
||||
return;
|
||||
}
|
||||
let create_location = value.value.created_at().unwrap();
|
||||
|
||||
Reference in new issue
Block a user