# `Xenia.Live`
[🔗](https://github.com/uzaydurdu/xenia/blob/v0.1.1/lib/xenia/app/live.ex#L1)

The shared LiveView of a `live.ex`: one LiveView owns every page in its
folder and below.

Switching between those pages is a `<.link patch>`: the same process keeps
its state, and `handle_params/3` runs with the new URL. The route's live
action is the page module, so by default this LiveView renders the current
page's `render/1` with its own assigns, inside the page's layouts.

```elixir
# app/settings/live.ex  →  owns /settings/profile and /settings/security
defmodule MyAppWeb.SettingsLive do
  use MyAppWeb, :live_view
  use Xenia.Live

  def mount(_params, _session, socket), do: {:ok, assign(socket, user: load_user())}

  def handle_params(_params, _uri, socket), do: {:noreply, socket}
end

# app/settings/profile/page.ex
defmodule MyAppWeb.ProfilePage do
  use MyAppWeb, :html

  def render(assigns), do: ~H"<h1>{@user.name}</h1>"
end
```

Define `render/1` yourself to put shared markup around the page; render
the page with `Xenia.Live.page/1`:

    def render(assigns) do
      ~H"""
      <nav>...tabs...</nav>
      {Xenia.Live.page(assigns)}
      """
    end

The owner handles every event and message; a page's own LiveView callbacks
don't run under it. Layouts' `on_mount` hooks run once, when the owner
mounts, so a `layout.ex` below the `live.ex` can't declare `on_mount`:
patching to its pages wouldn't run them. `xenia_routes` rejects that at
compile time.

# `page`

```elixir
@spec page(map()) :: Phoenix.LiveView.Rendered.t()
```

Renders the current page, the route's live action, with the owner's
assigns, without layouts (the owner adds them once around its whole
render).

---

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