fsmx v0.5.0 Fsmx.Fsm behaviour View Source
Holds transition and callback logic for finite state machines
By default, when using use Fsmx.Struct
, this is automatically included as well.
Specifying use Fsmx.Struct, fsm: MyApp.Fsm
allows you to decouple this, though
defmodule MyApp.Struct do
defstruct [:state]
end
defmodule MyApp.Fsm do
use Fsmx.Fsm, transitions: %{}
def before_transition(struct, _from, _to, _state_field) do
# ...
end
end
Callbacks
Callbacks are defined as functions in the module that includes Fsmx.Fsm
(which could be the one that includes Fsmx.Struct
). They are called with
the struct, the current state, the new state, and the state field name. This
allows for different callbacks per state field.
The following callbacks are deprecated and will be removed in a future:
before_transition/3
transition_changeset/4
after_transition_multi/3
Link to this section Summary
Link to this section Functions
Link to this section Callbacks
Specs
after_transition_multi(struct(), Fsmx.state_t(), Fsmx.state_t(), atom()) :: {:ok, struct()} | {:error, any()}
Specs
before_transition(struct(), Fsmx.state_t(), Fsmx.state_t(), atom()) :: {:ok, struct()} | {:error, any()}
Specs
transition_changeset( Ecto.Schema.t(), Fsmx.state_t(), Fsmx.state_t(), map(), atom() ) :: Ecto.Changeset.t()