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
@@ -35,20 +35,25 @@ struct RootRouterContext(Signal<Option<RouterContext>>);
|
||||
///
|
||||
/// This will return `None` if there is no router present or the router has not been created yet.
|
||||
pub fn root_router() -> Option<RouterContext> {
|
||||
if let Some(ctx) = ScopeId::ROOT.consume_context::<RootRouterContext>() {
|
||||
let rt = dioxus_core::Runtime::current();
|
||||
|
||||
if let Some(ctx) = rt.consume_context::<RootRouterContext>(ScopeId::ROOT) {
|
||||
ctx.0.cloned()
|
||||
} else {
|
||||
ScopeId::ROOT.provide_context(RootRouterContext(Signal::new_in_scope(None, ScopeId::ROOT)));
|
||||
rt.provide_context(
|
||||
ScopeId::ROOT,
|
||||
RootRouterContext(Signal::new_in_scope(None, ScopeId::ROOT)),
|
||||
);
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn provide_router_context(ctx: RouterContext) {
|
||||
if root_router().is_none() {
|
||||
ScopeId::ROOT.provide_context(RootRouterContext(Signal::new_in_scope(
|
||||
Some(ctx),
|
||||
dioxus_core::Runtime::current().provide_context(
|
||||
ScopeId::ROOT,
|
||||
)));
|
||||
RootRouterContext(Signal::new_in_scope(Some(ctx), ScopeId::ROOT)),
|
||||
);
|
||||
}
|
||||
provide_context(ctx);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user