pub struct ScopeId(pub usize);
Expand description
A component’s unique identifier.
ScopeId
is a usize
that acts a key for the internal slab of Scopes. This means that the key is not unique across
time. We do try and guarantee that between calls to wait_for_work
, no ScopeIds will be recycled in order to give
time for any logic that relies on these IDs to properly update.
Tuple Fields§
§0: usize
Implementations§
Source§impl ScopeId
impl ScopeId
Sourcepub fn owner<S: AnyStorage>(self) -> Owner<S>
pub fn owner<S: AnyStorage>(self) -> Owner<S>
Get the owner for the current scope.
Source§impl ScopeId
impl ScopeId
Sourcepub fn current_scope_id(self) -> Result<ScopeId, RuntimeError>
pub fn current_scope_id(self) -> Result<ScopeId, RuntimeError>
Get the current scope id
Sourcepub fn consume_context<T: 'static + Clone>(self) -> Option<T>
pub fn consume_context<T: 'static + Clone>(self) -> Option<T>
Consume context from the current scope
Sourcepub fn consume_context_from_scope<T: 'static + Clone>(
self,
scope_id: ScopeId,
) -> Option<T>
pub fn consume_context_from_scope<T: 'static + Clone>( self, scope_id: ScopeId, ) -> Option<T>
Consume context from the current scope
Sourcepub fn has_context<T: 'static + Clone>(self) -> Option<T>
pub fn has_context<T: 'static + Clone>(self) -> Option<T>
Check if the current scope has a context
Sourcepub fn provide_context<T: 'static + Clone>(self, value: T) -> T
pub fn provide_context<T: 'static + Clone>(self, value: T) -> T
Provide context to the current scope
Sourcepub fn push_future(
self,
fut: impl Future<Output = ()> + 'static,
) -> Option<Task>
pub fn push_future( self, fut: impl Future<Output = ()> + 'static, ) -> Option<Task>
Pushes the future onto the poll queue to be polled after the component renders.
Sourcepub fn spawn(self, fut: impl Future<Output = ()> + 'static)
pub fn spawn(self, fut: impl Future<Output = ()> + 'static)
Spawns the future but does not return the Task
Sourcepub fn generation(self) -> Option<usize>
pub fn generation(self) -> Option<usize>
Get the current render since the inception of this component
This can be used as a helpful diagnostic when debugging hooks/renders, etc
Sourcepub fn parent_scope(self) -> Option<ScopeId>
pub fn parent_scope(self) -> Option<ScopeId>
Get the parent of the current scope if it exists
Sourcepub fn is_descendant_of(self, other: ScopeId) -> bool
pub fn is_descendant_of(self, other: ScopeId) -> bool
Check if the current scope is a descendant of the given scope
Sourcepub fn needs_update(self)
pub fn needs_update(self)
Mark the current scope as dirty, causing it to re-render
Sourcepub fn schedule_update(&self) -> Arc<dyn Fn() + Send + Sync + 'static>
pub fn schedule_update(&self) -> Arc<dyn Fn() + Send + Sync + 'static>
Create a subscription that schedules a future render for the reference component. Unlike Self::needs_update
, this function will work outside of the dioxus runtime.
§Notice: you should prefer using crate::prelude::schedule_update_any
Sourcepub fn in_runtime<T>(self, f: impl FnOnce() -> T) -> T
pub fn in_runtime<T>(self, f: impl FnOnce() -> T) -> T
Run a closure inside of scope’s runtime
Sourcepub fn throw_error(self, error: impl Into<CapturedError> + 'static)
pub fn throw_error(self, error: impl Into<CapturedError> + 'static)
Throw a CapturedError
into a scope. The error will bubble up to the nearest [ErrorBoundary
] or the root of the app.
§Examples
fn Component() -> Element {
let request = spawn(async move {
match reqwest::get("https://api.example.com").await {
Ok(_) => unimplemented!(),
// You can explicitly throw an error into a scope with throw_error
Err(err) => ScopeId::APP.throw_error(err)
}
});
unimplemented!()
}
Source§impl ScopeId
impl ScopeId
Sourcepub const APP: ScopeId
pub const APP: ScopeId
The ScopeId of the main scope passed into [VirtualDom::new
].
This scope will last for the entire duration of your app, making it convenient for long-lived state that is created dynamically somewhere down the component tree.
§Example
use dioxus::prelude::*;
let my_persistent_state = Signal::new_in_scope(String::new(), ScopeId::APP);
Sourcepub const ROOT: ScopeId
pub const ROOT: ScopeId
The ScopeId of the topmost scope in the tree.
This will be higher up in the tree than ScopeId::APP
because dioxus inserts a default [SuspenseBoundary
] and [ErrorBoundary
] at the root of the tree.