# `LiveStash.Adapter`
[🔗](https://github.com/software-mansion-labs/live-stash/blob/v0.1.2/lib/live_stash/adapter.ex#L1)

Behaviour for storage backends used by `LiveStash`.

An adapter is responsible for persisting and restoring selected LiveView
assigns for a specific socket identity. `LiveStash` delegates all storage
operations to the adapter chosen during initialization.

# `recovery_status`

```elixir
@type recovery_status() :: :recovered | :not_found | :new | :error
```

# `child_spec`
*optional* 

```elixir
@callback child_spec(args :: any()) :: Supervisor.child_spec()
```

Returns a child specification when the adapter needs supervision.

# `init_stash`

```elixir
@callback init_stash(
  socket :: Phoenix.LiveView.Socket.t(),
  session :: Keyword.t(),
  opts :: Keyword.t()
) ::
  Phoenix.LiveView.Socket.t()
```

Initializes adapter state for the given socket.

Called during LiveView mount through `LiveStash.on_mount/4`.
Receives session data and adapter options and must return an updated socket.

# `recover_state`

```elixir
@callback recover_state(socket :: Phoenix.LiveView.Socket.t()) ::
  {recovery_status(), Phoenix.LiveView.Socket.t()}
```

Attempts to restore previously persisted state to the socket.

Must return `{status, socket}` where `status` is one of
`t:recovery_status/0`.

# `reset_stash`

```elixir
@callback reset_stash(socket :: Phoenix.LiveView.Socket.t()) ::
  Phoenix.LiveView.Socket.t()
```

Removes stored state associated with the socket and returns it.

# `stash_assigns`

```elixir
@callback stash_assigns(socket :: Phoenix.LiveView.Socket.t(), keys :: [atom()]) ::
  Phoenix.LiveView.Socket.t()
```

Persists selected assign keys for the given socket.

The keys are atoms that reference entries in `socket.assigns`.
Returns an updated socket.

---

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