Skip to main content

GlobalState

Struct GlobalState 

Source
pub struct GlobalState;
Expand description

App-wide reactive global state registry supporting type-keyed and named singleton stores plus scope-aware watch observers.

Implementations§

Source§

impl GlobalState

Global singleton state registration, access, mutation, and scope-aware change watching for GlobalState.

Source

pub fn provide<T>(initial: T) -> Signal<T>
where T: 'static,

Registers or replaces a type-keyed root-lifetime global state value of type T.

§Arguments
  • T - Initial or replacement global state value.
§Returns
  • Signal<T> - Root-lifetime reactive signal bound to global type T.
Source

pub fn use_state<T>() -> Option<Signal<T>>
where T: 'static,

Looks up a previously registered global state signal of type T.

§Returns
  • Option<Signal<T>> - Registered global signal if present.
Source

pub fn use_or_init<T, F>(init: F) -> Signal<T>
where T: 'static, F: FnOnce() -> T,

Returns the registered global state signal of type T, lazily initializing it with init when absent.

§Arguments
  • F - Lazy initializer invoked only when global state T has not yet been registered.
§Returns
  • Signal<T> - Root-lifetime reactive signal for global state T.
Source

pub fn get<T>() -> Option<T>
where T: Clone + 'static,

Reactively reads the current value of global state T, tracking dependency on the active observer.

§Returns
  • Option<T> - Current global state value if registered.
Source

pub fn get_untracked<T>() -> Option<T>
where T: Clone + 'static,

Reads the current value of global state T without tracking reactive dependencies.

§Returns
  • Option<T> - Current global state value if registered.
Source

pub fn set<T>(value: T) -> bool
where T: 'static,

Replaces the registered global state T and notifies all active observers.

§Arguments
  • T - Replacement global state value.
§Returns
  • bool - true when global state T existed and was updated.
Source

pub fn set_if_changed<T>(value: T) -> bool
where T: PartialEq + 'static,

Replaces global state T only when value differs from the stored value.

§Arguments
  • T - Candidate replacement value.
§Returns
  • bool - true when the state changed.
Source

pub fn update<T, F>(updater: F) -> bool
where T: Clone + 'static, F: FnOnce(&mut T),

Mutates global state T in place via updater.

§Arguments
  • F - Mutation closure.
§Returns
  • bool - true when global state T existed and was mutated.
Source

pub fn watch<T, F>(handler: F) -> Option<Effect>
where T: Clone + 'static, F: FnMut(&T, &T) + 'static,

Subscribes a scope-owned change watcher receiving (&previous, &next) whenever global state T updates.

§Arguments
  • F - Change callback (automatically suspended when owning page is frozen and coalesced on resume).
§Returns
  • Option<Effect> - Watcher effect handle if global state T is registered.
Source

pub fn provide_named<T>(name: &str, initial: T) -> Signal<T>
where T: 'static,

Registers or replaces a string-keyed global state channel storing T.

§Arguments
  • &str - Channel name.
  • T - Initial or replacement value.
§Returns
  • Signal<T> - Root-lifetime signal handle.
Source

pub fn use_named<T>(name: &str) -> Option<Signal<T>>
where T: 'static,

Looks up a string-keyed global state channel storing T.

§Arguments
  • &str - Channel name.
§Returns
  • Option<Signal<T>> - Registered signal handle if present.
Source

pub fn watch_named<T, F>(name: &str, handler: F) -> Option<Effect>
where T: Clone + 'static, F: FnMut(&T, &T) + 'static,

Subscribes a scope-owned watcher receiving (&previous, &next) for a string-keyed global state channel.

§Arguments
  • &str - Channel name.
  • F - Change callback.
§Returns
  • Option<Effect> - Watcher effect handle if the named channel exists.

Trait Implementations§

Source§

impl Clone for GlobalState

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for GlobalState

Source§

impl Debug for GlobalState

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for GlobalState

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for GlobalState

Source§

impl PartialEq for GlobalState

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for GlobalState

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.