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>(self) -> Owner<S>where
S: AnyStorage,
pub fn owner<S>(self) -> Owner<S>where
S: AnyStorage,
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>(self) -> Option<T>where
T: 'static + Clone,
pub fn consume_context<T>(self) -> Option<T>where
T: 'static + Clone,
Consume context from the current scope
sourcepub fn consume_context_from_scope<T>(self, scope_id: ScopeId) -> Option<T>where
T: 'static + Clone,
pub fn consume_context_from_scope<T>(self, scope_id: ScopeId) -> Option<T>where
T: 'static + Clone,
Consume context from the current scope
sourcepub fn has_context<T>(self) -> Option<T>where
T: 'static + Clone,
pub fn has_context<T>(self) -> Option<T>where
T: 'static + Clone,
Check if the current scope has a context
sourcepub fn provide_context<T>(self, value: T) -> Twhere
T: 'static + Clone,
pub fn provide_context<T>(self, value: T) -> Twhere
T: 'static + Clone,
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() + Sync + Send>
pub fn schedule_update(&self) -> Arc<dyn Fn() + Sync + Send>
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.
Trait Implementations§
source§impl Ord for ScopeId
impl Ord for ScopeId
source§impl PartialOrd for ScopeId
impl PartialOrd for ScopeId
impl Copy for ScopeId
impl Eq for ScopeId
impl StructuralPartialEq for ScopeId
Auto Trait Implementations§
impl Freeze for ScopeId
impl RefUnwindSafe for ScopeId
impl Send for ScopeId
impl Sync for ScopeId
impl Unpin for ScopeId
impl UnwindSafe for ScopeId
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)