ex_state v2.0.1 ExState View Source

Elixir state machines and statecharts

Usage

iex> definition = %{
iex>   id: "toggle",
iex>   initial: :inactive,
iex>   states: %{
iex>     inactive: %{
iex>       on: %{
iex>         TOGGLE: %{
iex>           target: :active
iex>         }
iex>       }
iex>     },
iex>     active: %{
iex>       on: %{
iex>         TOGGLE: %{
iex>           target: :inactive
iex>         }
iex>       }
iex>     }
iex>   }
iex> }
iex> machine = ExState.machine(definition)  # and now create state machine
iex> ExState.transition(machine, :TOGGLE)  # and transit to new state
%ExState.Machine{
  context: nil,
  id: "toggle",
  initial: :inactive,
  options: %ExState.Options{actions: nil, guards: nil},
  state: %ExState.State{
    context: nil,
    event: %ExState.Event{data: nil, type: :TOGGLE},
    value: :active
  },
  states: %{
    active: %ExState.NodeType.Atomic{
      on: %{
        TOGGLE: %ExState.Transition{actions: [], cond: nil, target: :inactive}
      }
    },
    inactive: %ExState.NodeType.Atomic{
      on: %{
        TOGGLE: %ExState.Transition{actions: [], cond: nil, target: :active}
      }
    }
  }
}

Link to this section Summary

Link to this section Functions