# `PhoenixDatastar.Server`
[🔗](https://github.com/RicoTrevisan/phoenix_datastar/blob/v0.1.16/lib/server.ex#L1)

GenServer for live PhoenixDatastar views.

Manages the socket state and handles:
- Event dispatching from client
- PubSub message forwarding to view's handle_info/2
- SSE updates to subscribers
- Cleanup on disconnect via terminate/1

# `child_spec`
[🔗](https://github.com/RicoTrevisan/phoenix_datastar/blob/v0.1.16/lib/server.ex#L12)

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `dispatch_event`
[🔗](https://github.com/RicoTrevisan/phoenix_datastar/blob/v0.1.16/lib/server.ex#L103)

```elixir
@spec dispatch_event(String.t(), String.t(), map()) :: :ok
```

Dispatches an event to the GenServer for handling.

This is an async cast - the response is sent via the SSE stream.

# `ensure_started`
[🔗](https://github.com/RicoTrevisan/phoenix_datastar/blob/v0.1.16/lib/server.ex#L46)

```elixir
@spec ensure_started(module(), String.t(), map(), map(), String.t()) ::
  {:ok, pid()} | {:error, term()}
```

Ensures a GenServer is started for the given session.

If already running, returns the existing pid. Idempotent.

# `enter_loop`
[🔗](https://github.com/RicoTrevisan/phoenix_datastar/blob/v0.1.16/lib/server.ex#L114)

```elixir
@spec enter_loop(PhoenixDatastar.SSE.t(), String.t()) :: PhoenixDatastar.SSE.t()
```

Enters the SSE loop, receiving updates from the GenServer and sending them to the client.
Takes a %PhoenixDatastar.SSE{} struct instead of a raw conn.

Returns the SSE struct when the connection closes.

# `get_snapshot`
[🔗](https://github.com/RicoTrevisan/phoenix_datastar/blob/v0.1.16/lib/server.ex#L77)

```elixir
@spec get_snapshot(String.t()) :: {:ok, String.t(), map()}
```

Get the current rendered HTML and initial signals without subscribing.

# `navigate`
[🔗](https://github.com/RicoTrevisan/phoenix_datastar/blob/v0.1.16/lib/server.ex#L93)

```elixir
@spec navigate(String.t(), module(), map(), String.t(), map()) :: :ok
```

Replaces the active view/socket state for an existing live session
and pushes the new content through the SSE stream.

## Nav meta

  * `:root_selector` - CSS selector for the content container (e.g., "#app")
  * `:target` - The target URL path
  * `:mode` - "push" or "replace" for history state
  * `:framework_signals` - Map of framework signals (session_id, event_path, nav_token, etc.)

# `start_link`
[🔗](https://github.com/RicoTrevisan/phoenix_datastar/blob/v0.1.16/lib/server.ex#L34)

```elixir
@spec start_link(keyword()) :: GenServer.on_start()
```

Starts a GenServer for a Datastar view session.

## Options

  * `:view` - Required. The view module.
  * `:session_id` - Required. Unique session identifier.
  * `:params` - Route params. Defaults to `%{}`.
  * `:session` - Plug session data. Defaults to `%{}`.
  * `:base_path` - Base path for event URLs. Defaults to `""`.

# `subscribe`
[🔗](https://github.com/RicoTrevisan/phoenix_datastar/blob/v0.1.16/lib/server.ex#L69)

```elixir
@spec subscribe(String.t()) :: :ok
```

Subscribe the calling process to receive render updates.
Does not return initial HTML (use get_snapshot/1 if needed).

---

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