pub struct RouteObserver { /* private fields */ }Expand description
The reactive route-state observable: RouteObserver is the signal
face over frust_widgets’ signal-free RouteStack/NavChange — the
counterpart to RouteNavigator (intent, queued requests) that reads
fact (the last-published stack) instead. Construct once (typically in
Component::init) and attach with
observe(navigator(...));
RouterDeepLinks::routes hands out the one it wired for a router-driven
navigator. See route_state’s module docs for why this bridge lives in
the facade rather than frust-widgets.
Reactive face of one navigator’s route stack: Copy + Send + Sync
(five RwSignals and nothing else), so it rides provide_context — the
navigator’s own NavigatorController/
Router never can (see
frust_widgets::nav::route’s module docs for why).
Implementations§
Source§impl RouteObserver
impl RouteObserver
Sourcepub fn new() -> Self
pub fn new() -> Self
A fresh observer at rest (NavChange::Initial, depth 0, generation 0,
no current route) — construct once, typically in Component::init,
and keep the result in State.
Sourcepub fn observe<State: 'static>(
self,
view: NavigatorView<State>,
) -> NavigatorView<State>
pub fn observe<State: 'static>( self, view: NavigatorView<State>, ) -> NavigatorView<State>
Attach: installs NavigatorView::on_route_change, writing these
signals from inside the navigator’s own rebuild whenever the published
RouteStack actually changes. Chainable and cheap to call again
(RouteObserver is Copy), so a second navigator elsewhere in the app
gets its own observer the same way:
state.routes.observe(navigator(&controller, initial)).
§Wake correctness
The write happens inside the navigator’s rebuild, after apply_ops:
a navigation requested in frame N is published in N, read by the app’s
build in N+1, and the write itself schedules N+1 — the same
tracked-write-wakes-the-shell bridge every other signal in the
framework rides (docs/CODE_STANDARDS.md’s tracked-scope rule), not a
manual ReactiveRuntime::wake() call. One frame behind is possible;
silently behind is not (a page transition runs ~300ms; 16ms of bar
lag is below the perceptual floor).
Sourcepub fn current(&self) -> Option<Location>
pub fn current(&self) -> Option<Location>
The topmost page that has a route — skips a route-less
(overlay/dialog) page on top, the read chrome (an app bar title, e.g.)
wants. Tracked read; see RouteStack::current_route’s doc for the
full contract.
Sourcepub fn path(&self) -> String
pub fn path(&self) -> String
current’s path, or an empty string before the first
publish (or if no page in the stack carries a route at all).
Sourcepub fn param(&self, key: &str) -> Option<String>
pub fn param(&self, key: &str) -> Option<String>
A query parameter off current’s location. None if
there is no current routed page, or the key is absent.
Sourcepub fn stack(&self) -> Vec<Option<Location>>
pub fn stack(&self) -> Vec<Option<Location>>
The full stack, bottom→top; None at a route-less (overlay/dialog)
page — the tracked-read mirror of RouteStack::entries.
Sourcepub fn is_back(&self) -> bool
pub fn is_back(&self) -> bool
Whether the most recent change was a NavChange::Pop — the
direction chrome resolves a title-transition from, e.g.
.title_direction(if routes.is_back() { Back } else { Forward }).
Trait Implementations§
Source§impl Clone for RouteObserver
impl Clone for RouteObserver
impl Copy for RouteObserver
Auto Trait Implementations§
impl Freeze for RouteObserver
impl RefUnwindSafe for RouteObserver
impl Send for RouteObserver
impl Sync for RouteObserver
impl Unpin for RouteObserver
impl UnsafeUnpin for RouteObserver
impl UnwindSafe for RouteObserver
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.