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

The convenience module, exposing `start_link/1` to embed `Finitomata.Supervisor`
implementation into a supervision tree in an agnostic way.

This module implements `Access` in a contrived way, allowing to deal with underlying
_FSM_ instances in a following way.

```elixir
iex|🌢|1 ▶ Finitomata.Accessible.start_link(type: Finitomata, implementation: L, id: L1)
{:ok, #PID<0.214.0>}

iex|🌢|2 ▶ sup = Finitomata.Accessible.lookup(L1)
%Finitomata.Accessible{
  type: Finitomata,
  id: L1,
  implementation: Finitomata.Test.Log,
  last_event: nil,
  cached_pid: #PID<0.214.0>
}

iex|🌢|3 ▶ put_in(sup, ["MyFSM"], :accept)
07:16:34.736 [debug] [→ ↹] […]
07:16:34.738 [debug] [✓ ⇄] with: [current: :*, event: :__start__, event_payload: %{payload: nil, __retries__: 1}, state: %{}]
07:16:34.738 [debug] [← ↹] […]
07:16:34.738 [debug] [→ ↹] […]
07:16:34.739 [debug] [✓ ⇄] with: [current: :idle, event: :accept, event_payload: nil, state: %{}]
07:16:34.739 [debug] [← ↹] […]

%Finitomata.Accessible{
  type: Finitomata,
  id: L1,
  implementation: Finitomata.Test.Log,
  last_event: {"MyFSM", :accept},
  cached_pid: #PID<0.214.0>
}

iex|🌢|4 ▶ get_in(sup, ["MyFSM"])
#Finitomata<[
  name: {Finitomata.L1.Registry, "MyFSM"},
  state: [current: :accepted, previous: :idle, payload: %{}],
  internals: [errored?: false, persisted?: false, timer: false]
]>
```

# `t`
*since 0.26.0* 

```elixir
@type t() :: %Finitomata.Accessible{
  type: Finitomata.Supervisor.t(),
  id: Finitomata.id(),
  implementation: module(),
  last_event: nil | {Finitomata.fsm_name(), Finitomata.event_payload()},
  cached_pid: nil | pid()
}
```

The convenience struct representing the `Finitomata.Supervisor` with `Access`

# `lookup`
*since 0.26.0* 

```elixir
@spec lookup(Finitomata.id()) :: t()
```

Looks up the `Finitomata.Accessible` instance for the given `id`

# `start_link`
*since 0.26.0* 

Supervision tree embedder.

## Options to `Finitomata.Accessible.start_link/1`

* `:type` - The actual `Finitomata.Supervisor` implementation (typically, `Finitomata` or `Infinitomata`) The default value is `Infinitomata`.

* `:implementation` (`t:atom/0`) - Required. The actual implementation of _FSM_ (the module, having `use Finitomata` clause)

* `:id` (`t:term/0`) - The unique `ID` of this _Finitomata_ “branch,” when `nil` the `implementation` value would be used The default value is `nil`.

---

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