pub struct Scope { /* private fields */ }Expand description
Where a segment’s state, features and resources live, from the moment it is installed until it is removed.
A name for one, and Copy: the ScopeTree it is in owns what each scope
holds, and nothing else does. Holding a Scope does not keep it alive, so
a scope goes exactly when remove is called on it or on a
scope above it - children first - or when its tree’s owner lets go of the
tree, and not whenever the last of whoever happened to be holding it lets
go.
A removed scope’s name never comes back: every scope is numbered once, so
an old Scope keeps naming the scope that is gone, and
is_alive says so.
Implementations§
Source§impl Scope
impl Scope
Sourcepub fn set_window(&self, id: u64)
pub fn set_window(&self, id: u64)
Says this scope is the root of window id, as RootId::get numbers
it: what devtools are told the actors under it belong to.
Sourcepub fn hold_actor<A: ManagedActor + Debug>(
&self,
addr: &Addr<A>,
feature: Option<&'static str>,
drives: Option<&'static str>,
)
pub fn hold_actor<A: ManagedActor + Debug>( &self, addr: &Addr<A>, feature: Option<&'static str>, drives: Option<&'static str>, )
Lists addr among the actors this scope holds, for devtools, until
the scope is removed - feature created it, and it drives drives
when it was made to.
Only the listing: what ends the actor is still whoever owns it, which
for an actor of a segment is own on this same scope.
Sourcepub fn actors(&self) -> Vec<ActorSnapshot>
pub fn actors(&self) -> Vec<ActorSnapshot>
The actors this scope and every scope under it hold, read now.
Sourcepub fn actor(&self, id: usize) -> Option<ActorSnapshot>
pub fn actor(&self, id: usize) -> Option<ActorSnapshot>
The actor id, if this scope or one under it holds it, read now; the
others are not read.
Sourcepub fn actors_here(&self) -> Vec<ActorSnapshot>
pub fn actors_here(&self) -> Vec<ActorSnapshot>
The actors this scope holds itself, read now - not those of the scopes under it.
Sourcepub fn actor_here(&self, id: usize) -> Option<ActorSnapshot>
pub fn actor_here(&self, id: usize) -> Option<ActorSnapshot>
The actor id, if this scope holds it itself, read now.
Source§impl Scope
impl Scope
Sourcepub fn mark_feature_installed<F: 'static>(&self)
pub fn mark_feature_installed<F: 'static>(&self)
Marks feature F (its install function, used purely as a type
identity) as owned by this scope. F must not already be marked
here - two different call sites both claiming ownership of the same
feature in the same scope is a setup bug, not something to merge
silently.
Sourcepub fn claims<R: 'static>(&self) -> bool
pub fn claims<R: 'static>(&self) -> bool
Whether anything in this scope has claimed R.
What tells an export that was earned from one that was only declared.
pub fn note_reducer_owner<R: 'static>(&self)
Sourcepub fn note_reducer_declared<R: 'static>(&self, declared: Declared)
pub fn note_reducer_declared<R: 'static>(&self, declared: Declared)
Notes where reducer R was claimed, the first claim winning.
Sourcepub fn current_crate_dir(&self) -> Option<&'static str>
pub fn current_crate_dir(&self) -> Option<&'static str>
The manifest directory of the feature installing now, for a claim that only knows the file the compiler gave it.
Sourcepub fn open_section(
&self,
name: Option<&'static str>,
declared: Option<Declared>,
) -> usize
pub fn open_section( &self, name: Option<&'static str>, declared: Option<Declared>, ) -> usize
Opens a section for what is about to install - the feature name, or
something that is not a feature, such as a plugin. Returns its index.
Sourcepub fn section_name(&self, section: usize) -> Option<&'static str>
pub fn section_name(&self, section: usize) -> Option<&'static str>
The feature a section belongs to; None for the segment’s own.
Sourcepub fn current_feature(&self) -> Option<&'static str>
pub fn current_feature(&self) -> Option<&'static str>
The feature being installed right now, if any.
Sourcepub fn note_listener(
&self,
event: &'static str,
actor: Option<&'static str>,
bus: Bus,
)
pub fn note_listener( &self, event: &'static str, actor: Option<&'static str>, bus: Bus, )
Notes that whatever is installing listens to event on bus - through
actor when an actor does the listening.
pub fn listeners(&self) -> Vec<Listener>
pub fn close_section(&self)
Sourcepub fn current_section(&self) -> usize
pub fn current_section(&self) -> usize
The section being installed, or the segment’s own when none is.
Sourcepub fn section_of<R: 'static>(&self) -> usize
pub fn section_of<R: 'static>(&self) -> usize
Which section owns R - the instance whose dispatcher a reader of R
should be handed.
Sourcepub fn has_feature<F: 'static>(&self) -> bool
pub fn has_feature<F: 'static>(&self) -> bool
Whether feature F was marked installed in this exact scope.
Sourcepub fn note_export<R: 'static>(&self)
pub fn note_export<R: 'static>(&self)
Marks R as readable from segments below this one.
Called by cx.install::<F>() for everything in F::Exports, and by
an application’s export::<R>(). A reducer a feature claimed but did not export stays
visible to the feature itself and invisible from below - which is the
whole difference between a feature and a folder.
Sourcepub fn answers<M: 'static>(&self, answer: impl Fn(M) + 'static)
pub fn answers<M: 'static>(&self, answer: impl Fn(M) + 'static)
Says that this scope answers M, and how.
Keyed by the action, not by whoever answers it - which is what keeps
the answerer out of every signature the UI touches. actor! calls this
for each handler it lists; a domain that runs on tasks, or a channel,
or a plain closure over a RefCell, calls it itself.
Sourcepub fn answerer<M: 'static>(&self, section: usize) -> Option<Rc<dyn Fn(M)>>
pub fn answerer<M: 'static>(&self, section: usize) -> Option<Rc<dyn Fn(M)>>
What answers M in one section of this scope, if anything does.
Sourcepub fn first_answerer<M: 'static>(&self) -> Option<Rc<dyn Fn(M)>>
pub fn first_answerer<M: 'static>(&self) -> Option<Rc<dyn Fn(M)>>
What answers M anywhere in this scope - the first feature that does,
in the order they installed. For a sender that knows the action and
not which state it was reading.
Source§impl Scope
impl Scope
pub fn own_subscription(&self, subscription: BusSubscription)
Sourcepub fn own<R: Teardown>(&self, resource: R)
pub fn own<R: Teardown>(&self, resource: R)
Binds any Teardown resource to this scope’s lifetime: it is torn
down when the scope is - at once, if the scope is already gone.
Sourcepub fn on_leave(&self, guard: impl Fn() -> Verdict + 'static)
pub fn on_leave(&self, guard: impl Fn() -> Verdict + 'static)
Asked before this scope is torn down by a navigation.
Registered during install, which is the whole reason leaving and
entering are declared in different places: on the way out the scope
exists, so the guard can read its own state - which is what “unsaved
changes” is. On the way in there is nothing to read yet.
Sourcepub fn leave_guards(&self) -> Vec<Rc<dyn Fn() -> Verdict>>
pub fn leave_guards(&self) -> Vec<Rc<dyn Fn() -> Verdict>>
The guards to ask, in the order they were registered.
Cloned out rather than borrowed: a guard is free to touch this scope, and the caller runs them while deciding.
Sourcepub fn sleep(&self)
pub fn sleep(&self)
Puts this scope to sleep: kept, with its state and actors, but deaf.
What it owns stops hearing anything while it sleeps - its timers skip
their ticks, its actors and callbacks are not told what the buses
carry - and nothing is queued for later: what happened meanwhile is
missed. A router does this to a keep segment it leaves.
Sourcepub fn wake(&self)
pub fn wake(&self)
Wakes this scope, then runs what asked to hear of it, in the order it asked.
Source§impl Scope
impl Scope
Sourcepub fn describe_states(&self) -> Vec<DescribedState>
pub fn describe_states(&self) -> Vec<DescribedState>
Every reducer this scope holds whose type it has seen, printed.
Sourcepub fn state<R: Reducer>(&self) -> Rc<Slot<R>>
pub fn state<R: Reducer>(&self) -> Rc<Slot<R>>
R’s state here, created from R::default() on first read.
A removed scope has no state to hand out: what comes back is a fresh default nobody else sees.
pub fn peek<R: Reducer>(&self) -> Option<Rc<Slot<R>>>
Sourcepub fn seed<R: Reducer>(&self, state: R)
pub fn seed<R: Reducer>(&self, state: R)
Sets R’s starting value instead of R::default(). Call before
anything else touches R in this scope - overwrites any existing cell,
dropping its listeners.
Sourcepub fn push<R: Reducer>(&self, update: R::Update)
pub fn push<R: Reducer>(&self, update: R::Update)
Applies msg to F’s state now, and marks the cell so its listeners
run at the next notify::drain.
The state is current the moment this returns; what waits is the redraw. Nothing a listener does - navigating, dropping scopes, sending to another actor - happens on the stack of whoever pushed. A no-op once the scope is removed.
Sourcepub fn observe<R: Reducer>(
&self,
callback: impl Fn(&R::Update) + 'static,
) -> Subscription
pub fn observe<R: Reducer>( &self, callback: impl Fn(&R::Update) + 'static, ) -> Subscription
Watches what happened to F, not merely that something did.
A listener from subscribe learns the cell changed
and reads the new state; an observer is handed the update itself, which
is what tells a rename apart from a whole new list. Runs during the
drain, before any listener, so state that depends on this one has
settled by the time anything draws.
pub fn subscribe<R: Reducer>( &self, callback: impl Fn() + 'static, ) -> Subscription
Sourcepub fn binding<R: Reducer>(&self) -> ReducerBinding<R>
pub fn binding<R: Reducer>(&self) -> ReducerBinding<R>
A handle to R’s state and actions in this scope, for code that reads
or watches them without being a UI hook. See crate::binding.
Sourcepub fn snapshot_states(&self) -> HashMap<TypeId, Rc<dyn Any>>
pub fn snapshot_states(&self) -> HashMap<TypeId, Rc<dyn Any>>
Returns a shallow clone of every reducer state currently held by this
scope, keyed by the reducer’s TypeId. Used by the router to cache
page state in memory while the page is not mounted.
Sourcepub fn restore_states(&self, states: HashMap<TypeId, Rc<dyn Any>>)
pub fn restore_states(&self, states: HashMap<TypeId, Rc<dyn Any>>)
Pre-populates reducer cells with previously cached states. This is the
inverse of snapshot_states: when a page is
remounted, restoring its state before install runs lets the page find
ready data instead of defaults.
Source§impl Scope
impl Scope
Sourcepub fn remove(&self)
pub fn remove(&self)
Removes this scope and every scope under it, now: children before their parent, and each one’s resources the last first.
From the moment this is called, every Scope naming them is dead.
Removing a scope that is already gone does nothing.
Sourcepub fn parent(&self) -> Option<Scope>
pub fn parent(&self) -> Option<Scope>
The scope this one sits under, if it has one and it is still there.
Sourcepub fn children_in(&self, outlet: Outlet) -> Vec<Scope>
pub fn children_in(&self, outlet: Outlet) -> Vec<Scope>
The scopes right under this one, in outlet, oldest first.
Sourcepub fn beside(&self) -> Vec<Scope>
pub fn beside(&self) -> Vec<Scope>
The scopes right under this one in any outlet but MAIN, oldest
first: what a layout mounts beside its chain.
Sourcepub fn owner_of<R: 'static>(&self) -> Option<Scope>
pub fn owner_of<R: 'static>(&self) -> Option<Scope>
Where R is read from here: this scope if it claimed R, or the
nearest one above that exports it.
The two ends are asked different questions on purpose. A segment may
read anything it claimed itself; what a scope above claimed is its own
business unless it said otherwise in Exports.
Sourcepub fn guard(&self) -> ScopeGuard
pub fn guard(&self) -> ScopeGuard
Removes this scope when the guard is dropped.