# `Finitomata.Persistency`
[🔗](https://github.com/am-kantox/finitomata/blob/v0.35.0/lib/finitomata/persistency.ex#L1)

The behaviour to be implemented by a persistent storage to be used
  with `Finitomata` (pass the implementation as `persistency: Impl.Module.Name`
  to `use Finitomata`.)

Once declared, the initial state would attempt to load the current state from
  the storage using `load/1` funtcion which should return the `{state, payload}`
  tuple.

# `transition_info`

```elixir
@type transition_info() :: %{
  from: Finitomata.Transition.state(),
  to: Finitomata.Transition.state(),
  event: Finitomata.Transition.event(),
  event_payload: Finitomata.event_payload(),
  object: Finitomata.State.payload()
}
```

# `load`

```elixir
@callback load(id :: Finitomata.fsm_name()) ::
  {:loaded | :created | :unknown, Finitomata.State.payload()}
```

The function to be called from `init/1` callback upon FSM start to load the state and payload
  from the persistent storage

# `store`

```elixir
@callback store(
  id :: Finitomata.fsm_name(),
  object :: Finitomata.State.payload(),
  transition :: transition_info()
) :: :ok | {:ok, Finitomata.State.payload()} | {:error, any()}
```

The function to be called from `on_transition/4` handler to allow storing the state
  and payload to the persistent storage

# `store_error`
*optional* 

```elixir
@callback store_error(
  id :: Finitomata.fsm_name(),
  object :: Finitomata.State.payload(),
  reason :: any(),
  transition :: transition_info()
) :: :ok | {:error, any()}
```

The function to be called from `on_transition/4` handler on non successful
  transition to allow storing the failed attempt to transition to the persistent storage

---

*Consult [api-reference.md](api-reference.md) for complete listing*
