StateMachine.Transition (state_machine v0.1.8)

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.

Summary

Functions

Private function for running 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.

True if transition is a loop, i.e. doesn't change state.

Given populated context and Transition structure, sequentially runs all callbacks along with actual state update

Private function for updating state.

Types

callback_pos()

@type callback_pos() :: :before | :after

t(model)

@type t(model) :: %StateMachine.Transition{
  after: [StateMachine.Callback.t(model)],
  before: [StateMachine.Callback.t(model)],
  from: atom(),
  guards: [StateMachine.Guard.t(model)],
  to: atom()
}

Functions

callback(ctx, pos)

@spec callback(StateMachine.Context.t(model), callback_pos()) ::
  StateMachine.Context.t(model)

Private function for running Transition callbacks.

finalize(ctx)

@spec finalize(StateMachine.Context.t(model)) :: StateMachine.Context.t(model)

Private function sets status to :done, unless it has failed before.

is_allowed?(ctx, transition)

@spec is_allowed?(StateMachine.Context.t(model), t(model)) :: boolean()

Checks if the transition is allowed in the current context. Returns boolean.

loop?(arg1)

@spec loop?(t(any())) :: boolean()

True if transition is a loop, i.e. doesn't change state.

passthrough(ctx)

@spec passthrough(StateMachine.Context.t(model)) :: t(model)

run(ctx)

@spec run(StateMachine.Context.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)

@spec update_state(StateMachine.Context.t(model)) :: StateMachine.Context.t(model)

Private function for updating state.