state_machine v0.1.3 StateMachine.Callback
Callback wraps a captured function, that can be called in a various points of a State Machine's lifecycle. Depending on return type (shape) of the callback, it can update the context or the model, or be ignored.
Link to this section Summary
Functions
Applying a single callback. There are three types of callbacks supported
Applying a chain of callbacks. Application only happens if status
hasn't been changed.
Link to this section Types
binary_t(model)
binary_t(model) ::
(model, StateMachine.Context.t(model) ->
{:ok, model}
| {:ok, StateMachine.Context.t(model)}
| {:error, any()}
| any())
binary_t(model) :: (model, StateMachine.Context.t(model) -> {:ok, model} | {:ok, StateMachine.Context.t(model)} | {:error, any()} | any())
side_effect_t()
side_effect_t() :: (() -> any())
side_effect_t() :: (() -> any())
t(model)
t(model) :: unary_t(model) | binary_t(model) | side_effect_t()
t(model) :: unary_t(model) | binary_t(model) | side_effect_t()
unary_t(model)
Link to this section Functions
apply_callback(ctx, cb, step)
apply_callback(StateMachine.Context.t(model), t(model), atom()) ::
StateMachine.Context.t(model)
apply_callback(StateMachine.Context.t(model), t(model), atom()) :: StateMachine.Context.t(model)
Applying a single callback. There are three types of callbacks supported:
Unary
A unary callback, receiving a model struct and that can be updated in current conetxt based on shape of the return:
{:ok, model}
— replaces model in the context{:error, e}
— stops the transition with a given errorany
— doesn't have any effect on the context
Binary
A binary callback, receiving a model struct and a context. Either can be updated depending on the shape of the return:
{:ok, context}
— replaces context completely{:ok, model}
— replaces model in the context{:error, e}
— stops the transition with a given errorany
— doesn't have any effect on the context
Side effects
A type of callback that does not expect any input and potentially produces a side effect.
Any return value is ignored, except for {:error, e}
that stops the transition with a given error.
apply_chain(ctx, cbs, step)
apply_chain(StateMachine.Context.t(model), [t(model)], atom()) ::
StateMachine.Context.t(model)
apply_chain(StateMachine.Context.t(model), [t(model)], atom()) :: StateMachine.Context.t(model)
Applying a chain of callbacks. Application only happens if status
hasn't been changed.