Elixir finite state machines and statecharts library.
- Adheres to the SCXML specification.
- Inspired by XState JS.
def deps do
[
{:ex_state, "~> 2.0.1"}
]
end
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}
}
}
}
}
Statecharts are a formalism for modeling stateful, reactive systems. This is useful for declaratively describing the behavior of your application, from the individual components to the overall application logic.
- Statecharts - A Visual Formalism for Complex Systems by David Harel
- The World of Statecharts by Erik Mogensen
- Pure UI by Guillermo Rauch
- Pure UI Control by Adam Solove
- Spectrum - Statecharts Community
TODO: Add license