# `Filament.Observable`

Behaviour for observable GenServer processes.

A GenServer that `use`s `Filament.Observable.GenServer` automatically satisfies
this behaviour. Implement the optional callbacks to customise subscription
acceptance and teardown.

# `handle_subscribe`
*optional* 

```elixir
@callback handle_subscribe(
  subscriber :: term(),
  state :: term()
) ::
  {:ok, initial_value :: term(), new_state :: term()}
  | {:error, reason :: term(), new_state :: term()}
```

Called when a new subscriber requests a subscription.

Return `{:ok, initial_value, new_state}` to accept.
`initial_value` is the raw server state sent back to the subscriber.

Return `{:error, reason, new_state}` to reject.

# `handle_unsubscribe`
*optional* 

```elixir
@callback handle_unsubscribe(subscriber :: term(), state :: term()) ::
  {:ok, new_state :: term()}
```

Called when a subscriber unsubscribes or its process terminates.

---

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