state_machine v0.1.2 StateMachine.Transition
Transition module gathers together all of the actions that happen around transition from the old state to the new state in response to an event.
Link to this section Summary
Functions
Private function for running after_transition
callbacks.
Private function for running before_transition
callbacks.
Private function sets status to :done, unless it has failed before.
Checks if the transition is allowed in the current context. Returns boolean.
Given populated context and Transition structure, sequentially runs all callbacks along with actual state update
Private function for updating state.
Link to this section Types
t(model)
t(model) :: %StateMachine.Transition{
after: [StateMachine.Callback.t(model)],
before: [StateMachine.Callback.t(model)],
from: atom(),
guards: [StateMachine.Guard.t(model)],
to: atom()
}
t(model) :: %StateMachine.Transition{ after: [StateMachine.Callback.t(model)], before: [StateMachine.Callback.t(model)], from: atom(), guards: [StateMachine.Guard.t(model)], to: atom() }
Link to this section Functions
after_(ctx, transition)
after_(StateMachine.Context.t(model), t(model)) ::
StateMachine.Context.t(model)
after_(StateMachine.Context.t(model), t(model)) :: StateMachine.Context.t(model)
Private function for running after_transition
callbacks.
before(ctx, transition)
before(StateMachine.Context.t(model), t(model)) ::
StateMachine.Context.t(model)
before(StateMachine.Context.t(model), t(model)) :: StateMachine.Context.t(model)
Private function for running before_transition
callbacks.
finalize(ctx)
finalize(StateMachine.Context.t(model)) :: StateMachine.Context.t(model)
finalize(StateMachine.Context.t(model)) :: StateMachine.Context.t(model)
Private function sets status to :done, unless it has failed before.
is_allowed?(ctx, transition)
is_allowed?(StateMachine.Context.t(model), t(model)) :: boolean()
is_allowed?(StateMachine.Context.t(model), t(model)) :: boolean()
Checks if the transition is allowed in the current context. Returns boolean.
run(ctx, transition)
run(StateMachine.Context.t(model), t(model)) :: StateMachine.Context.t(model)
run(StateMachine.Context.t(model), t(model)) :: StateMachine.Context.t(model)
Given populated context and Transition structure, sequentially runs all callbacks along with actual state update:
- before(event)
- before(transition)
- before_leave(state)
- before_enter(state)
- (state update)
- after_leave(state)
- after_enter(state)
- after(transition)
- after(event)
If any of the callbacks fails, all sequential ops are cancelled.
update_state(ctx)
update_state(StateMachine.Context.t(model)) :: StateMachine.Context.t(model)
update_state(StateMachine.Context.t(model)) :: StateMachine.Context.t(model)
Private function for updating state.