state_machine v0.1.3 StateMachine.Event
Event is a container for transitions. It is identified by name (atom) and can contain arbitrary number of transtitions.
One important thing is that it's disallowed to have more than one unguarded transition from the state, since this would introduce a "non-determinism" (or rather just discard the latter transition). We loosely allow guarded transitions from the same state, but it doesn't guarantee anything: if guards always return true, we're back to where we were before.
Link to this section Summary
Functions
Private function for running after_event
callbacks.
Private function for running before_event
callbacks.
Checks if the event is allowed in the current context. First it makes sure that all guards
of the event return true
, then it scans transitions for the matching one. Match is determined
by the source state and passing of all guards as well.
This is an entry point for transition. By running this function with populated context, event and optional payload, you tell state machine to try to move to the next state. It returns an updated context.
Link to this section Types
t(model)
t(model) :: %StateMachine.Event{
after: [StateMachine.Callback.t(model)],
before: [StateMachine.Callback.t(model)],
guards: [StateMachine.Guard.t(model)],
name: atom(),
transitions: [StateMachine.Transition.t(model)]
}
t(model) :: %StateMachine.Event{ after: [StateMachine.Callback.t(model)], before: [StateMachine.Callback.t(model)], guards: [StateMachine.Guard.t(model)], name: atom(), transitions: [StateMachine.Transition.t(model)] }
Link to this section Functions
after_(ctx)
after_(StateMachine.Context.t(model)) :: StateMachine.Context.t(model)
after_(StateMachine.Context.t(model)) :: StateMachine.Context.t(model)
Private function for running after_event
callbacks.
before(ctx)
before(StateMachine.Context.t(model)) :: StateMachine.Context.t(model)
before(StateMachine.Context.t(model)) :: StateMachine.Context.t(model)
Private function for running before_event
callbacks.
is_allowed?(ctx, event)
is_allowed?(StateMachine.Context.t(model), t(model) | atom()) :: boolean()
is_allowed?(StateMachine.Context.t(model), t(model) | atom()) :: boolean()
Checks if the event is allowed in the current context. First it makes sure that all guards
of the event return true
, then it scans transitions for the matching one. Match is determined
by the source state and passing of all guards as well.
trigger(ctx, event, payload \\ nil)
trigger(StateMachine.Context.t(model), atom(), any()) ::
StateMachine.Context.t(model)
trigger(StateMachine.Context.t(model), atom(), any()) :: StateMachine.Context.t(model)
This is an entry point for transition. By running this function with populated context, event and optional payload, you tell state machine to try to move to the next state. It returns an updated context.