# `PhoenixReplay.Recording.Timeline`
[🔗](https://github.com/elixir-vibe/phoenix_replay/blob/v0.6.2/lib/phoenix_replay/recording/timeline.ex#L1)

Navigates a recording's events by index, and knows what the replay
shows at each: the view's assigns, its LiveComponents' assigns, the page
URL and the browser viewport.

A timeline is a cursor. `seek/2` moves it forward by applying only the
events in between, so playing a recording event by event costs one event
a step; moving back starts over from the beginning.

# `indexed`

```elixir
@type indexed() :: {PhoenixReplay.Recording.Event.t(), non_neg_integer()}
```

An event with its index in the recording.

# `interaction`

```elixir
@type interaction() :: {indexed(), [indexed()]}
```

An event that starts an interaction, and the events it caused.

# `t`

```elixir
@type t() :: %PhoenixReplay.Recording.Timeline{
  assigns: map(),
  before: map(),
  components: %{required({module(), term()}) =&gt; map()},
  event: PhoenixReplay.Recording.Event.t() | nil,
  events: tuple(),
  index: integer(),
  start: %{
    url: String.t() | nil,
    viewport: PhoenixReplay.Recording.viewport() | nil
  },
  url: String.t() | nil,
  viewport: PhoenixReplay.Recording.viewport() | nil
}
```

A position in a recording:

  * `:index` — the current event's index, `-1` before the first
  * `:event` — the current event, or `nil`
  * `:assigns` — the view's assigns after it, with the client state
    reported up to it merged into the reserved
    `PhoenixReplay.Recording.State.assign/0`
  * `:before` — the view's assigns before it, which the event changed
    into `:assigns`
  * `:components` — LiveComponent assigns after it, keyed by
    `{module, id}`
  * `:url` — the page URL: the last navigation up to it, or the URL the
    session started on
  * `:viewport` — the last `:viewport` event up to it, or the viewport
    the session connected with, if known

# `at`

```elixir
@spec at(PhoenixReplay.Recording.t(), integer()) :: t()
```

A timeline of `recording` at the event at `index`.

# `duration_ms`

```elixir
@spec duration_ms(PhoenixReplay.Recording.t()) :: non_neg_integer()
```

Offset of the last event in milliseconds.

# `first_render_index`

```elixir
@spec first_render_index(PhoenixReplay.Recording.t()) :: non_neg_integer()
```

Index of the first event after which the view can be rendered.

The recorder attaches before the view's own `mount/3` runs, so the view's
assigns first appear with the initial render.

# `for_playback`

```elixir
@spec for_playback(PhoenixReplay.Recording.t()) ::
  {PhoenixReplay.Recording.t(), PhoenixReplay.Recording.PointerTrack.t()}
```

Lays a recording out for playback, the same way for the player and its
frame, so an index means the same event in both: the pointer track is
taken out, to be drawn over the frame, and client state is spread into
an event per entry. See `PhoenixReplay.Recording.PointerTrack.split/1`
and `PhoenixReplay.Recording.State.spread/1`.

# `index_at`

```elixir
@spec index_at(PhoenixReplay.Recording.t(), non_neg_integer()) :: non_neg_integer()
```

Index of the last event at or before `time`, in milliseconds, but not
before the first render: where the player stands at that moment.

# `interactions`

```elixir
@spec interactions([PhoenixReplay.Recording.Event.t()]) :: [interaction()]
```

Groups events into interactions: a mount, user event, navigation or
message, followed by the renders, component updates and collected events
it caused. Events before the first one form an interaction of their own.

# `last_index`

```elixir
@spec last_index(PhoenixReplay.Recording.t() | t()) :: non_neg_integer()
```

Index of the last event, or `0` for an empty recording.

# `new`

```elixir
@spec new(PhoenixReplay.Recording.t()) :: t()
```

A timeline of `recording`, before its first event.

# `next`

```elixir
@spec next(t()) :: PhoenixReplay.Recording.Event.t() | nil
```

The event after the current one, or `nil` after the last.

# `seek`

```elixir
@spec seek(t(), integer()) :: t()
```

Moves to the event at `index`, clamped to the recording's range.

---

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