pub struct Store<State, Service, Action> {
reducer: Reducer<State, Action>,
effects: Effects<State, Service, Action>,
pub state: StateWrapper<State>,
pub service: Service,
initial_monotonic_time: Instant,
initial_time: Timestamp,
recursion_depth: u32,
last_action_id: ActionId,
}Expand description
Main struct for the state machine.
Exposes a Store::dispatch method, using
which actions can be dispatched, which triggers a
Fields§
§reducer: Reducer<State, Action>§effects: Effects<State, Service, Action>§state: StateWrapper<State>Current State.
Immutable access can be gained using store.state.get().
Mutation can only happen inside reducer.
service: Service§initial_monotonic_time: Instant§initial_time: Timestamp§recursion_depth: u32Current recursion depth of dispatch.
last_action_id: ActionIdImplementations§
Source§impl<State, Service, Action> Store<State, Service, Action>where
Service: TimeService,
Action: EnablingCondition<State>,
impl<State, Service, Action> Store<State, Service, Action>where
Service: TimeService,
Action: EnablingCondition<State>,
Sourcepub fn new(
reducer: Reducer<State, Action>,
effects: Effects<State, Service, Action>,
service: Service,
initial_time: SystemTime,
initial_state: State,
) -> Self
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.
pub fn service(&mut self) -> &mut Service
Sourcepub fn monotonic_to_time(&self, monotonic_time: Instant) -> u64
pub fn monotonic_to_time(&self, monotonic_time: Instant) -> u64
Convert monotonic time to system clock in nanoseconds from epoch.
Sourcepub fn dispatch<T>(&mut self, action: T) -> boolwhere
T: Into<Action> + EnablingCondition<State>,
pub fn dispatch<T>(&mut self, action: T) -> boolwhere
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.
pub fn dispatch_callback<T>(&mut self, callback: Callback<T>, args: T) -> bool
Sourcepub fn sub_dispatch<A, S>(&mut self, action: A) -> bool
pub fn sub_dispatch<A, S>(&mut self, action: A) -> bool
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.
fn update_action_id(&mut self) -> ActionId
Sourcefn dispatch_enabled(&mut self, action: Action)
fn dispatch_enabled(&mut self, action: Action)
Dispatches action without checking the enabling condition.
Sourcefn dispatch_reducer(
&mut self,
action_with_id: &ActionWithMeta<Action>,
dispatcher: &mut Dispatcher<Action, State>,
)
fn dispatch_reducer( &mut self, action_with_id: &ActionWithMeta<Action>, dispatcher: &mut Dispatcher<Action, State>, )
Runs the reducer.
Sourcefn dispatch_effects(
&mut self,
action_with_id: ActionWithMeta<Action>,
queued: Dispatcher<Action, State>,
)
fn dispatch_effects( &mut self, action_with_id: ActionWithMeta<Action>, queued: Dispatcher<Action, State>, )
Runs the effects.