Store

Struct Store 

Source
pub struct Store<State, Service, Action> {
    pub state: StateWrapper<State>,
    pub service: Service,
    /* private fields */
}
Expand description

Main struct for the state machine.

Exposes a Store::dispatch method, using which actions can be dispatched, which triggers a

  1. Reducer - to update the state.
  2. Effects - to trigger side-effects of the action.

Fields§

§state: StateWrapper<State>

Current State.

Immutable access can be gained using store.state.get(). Mutation can only happen inside reducer.

§service: Service

Implementations§

Source§

impl<State, Service, Action> Store<State, Service, Action>
where Service: TimeService, Action: EnablingCondition<State>,

Source

pub fn new( reducer: Reducer<State, Action>, effects: Effects<State, Service, Action>, service: Service, initial_time: SystemTime, initial_state: State, ) -> Self

Creates a new store.

Source

pub fn state(&self) -> &State

Returns the current state.

Source

pub fn service(&mut self) -> &mut Service

Source

pub fn monotonic_to_time(&self, monotonic_time: Instant) -> u64

Convert monotonic time to system clock in nanoseconds from epoch.

Source

pub fn dispatch<T>(&mut self, action: T) -> bool
where T: Into<Action> + EnablingCondition<State>,

Dispatch an Action.

Returns true if the action was enabled, hence if it was dispatched to reducer and then effects.

If action is not enabled, we return false and do nothing.

Source

pub fn dispatch_callback<T>(&mut self, callback: Callback<T>, args: T) -> bool
where T: 'static, Action: From<AnyAction> + EnablingCondition<State>,

Source

pub fn sub_dispatch<A, S>(&mut self, action: A) -> bool
where A: Into<<Self as SubStore<State, S>>::SubAction> + EnablingCondition<S>, <Self as SubStore<State, S>>::SubAction: Into<Action>, Self: SubStore<State, S>,

Dispatch an Action (For SubStore).

Returns true if the action was enabled, hence if it was dispatched to reducer and then effects.

If action is not enabled, we return false and do nothing.

Trait Implementations§

Source§

impl<State, Service, Action> Clone for Store<State, Service, Action>
where State: Clone, Service: Clone, Action: Clone + EnablingCondition<State>,

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<State, Service, Action> Freeze for Store<State, Service, Action>
where Service: Freeze, State: Freeze,

§

impl<State, Service, Action> RefUnwindSafe for Store<State, Service, Action>
where Service: RefUnwindSafe, State: RefUnwindSafe,

§

impl<State, Service, Action> Send for Store<State, Service, Action>
where Service: Send, State: Send,

§

impl<State, Service, Action> Sync for Store<State, Service, Action>
where Service: Sync, State: Sync,

§

impl<State, Service, Action> Unpin for Store<State, Service, Action>
where Service: Unpin, State: Unpin,

§

impl<State, Service, Action> UnwindSafe for Store<State, Service, Action>
where Service: UnwindSafe, State: UnwindSafe,

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.