Current section

Files

Jump to
live_debugger lib live_debugger structs trace diff_trace.ex
Raw

lib/live_debugger/structs/trace/diff_trace.ex

defmodule LiveDebugger.Structs.Trace.DiffTrace do
@moduledoc """
This module provides a struct to represent a LiveView diff that is sent to the client.
* `id` - unique id of the diff
* `pid` - pid of the LiveView
* `timestamp` - timestamp of the diff
* `body` - body of the diff
* `size` - size of the diff in bytes
"""
alias LiveDebugger.Structs.Trace
defstruct [
:id,
:pid,
:timestamp,
:body,
:size
]
@type t() :: %__MODULE__{
id: Trace.id(),
pid: pid(),
timestamp: non_neg_integer(),
body: map(),
size: non_neg_integer()
}
@doc """
Creates a new LiveView diff struct.
"""
@spec new(Trace.id(), map(), pid(), :erlang.timestamp(), non_neg_integer()) :: t()
def new(id, body, pid, timestamp, size) do
%__MODULE__{
id: id,
body: body,
pid: pid,
timestamp: :timer.now_diff(timestamp, {0, 0, 0}),
size: size
}
end
end