KartaWeb. LiveUpdates behaviour
(Karta v1.0.0)
Admin pages that update by themselves while they are open (see the
Live updates guide). A page loads its record with KartaWeb.Authorize,
then names it here with the kinds of change it shows:
on_mount {KartaWeb.Authorize, :server}
on_mount {KartaWeb.LiveUpdates, {:server, kinds: [:message_accepted, :recipients]}}
@behaviour KartaWeb.LiveUpdates
@impl KartaWeb.LiveUpdates
def refresh(socket, changes), do: ...When the LiveView is connected, it subscribes to the record's topic
(Karta.Changes.subscribe/1, with the record Authorize loaded:
:organisation, :server, :domain or :message). An announcement
(%Karta.Changes.Change{}) is never rendered. One of a kind the page
shows marks the page dirty (its kinds and ids) and schedules one
:refresh an interval later (config :karta, KartaWeb.LiveUpdates, interval:, default 1 second; every: 5 for five intervals), however
many announcements come before it; the other kinds wake nothing. At the
refresh, after KartaWeb.UserAuth has read the session and the scope
again, the page's organisation and server are loaded again for that
scope (KartaWeb.Authorize.load!/3; the domain too, on a domain's page):
a user who may no longer see them leaves for the start page. Then the page's refresh/2 reads what it
shows again, through its own scoped query.
Assigns: :refreshes, how many refreshes the page has had (it names
the highlight of changed rows, KartaWeb.CoreComponents.changed_class/1).
A page that reconnects mounts again and reads everything fresh; nothing
is replayed.
Summary
Types
What changed since the last refresh: the kinds announced, and the ids,
or :all when more than 100 were announced (the page then reads its
whole view again).
Callbacks
Reads again what the page shows, after changes.
Types
@type changes() :: %{kinds: MapSet.t(atom()), ids: MapSet.t(Ecto.UUID.t()) | :all}
What changed since the last refresh: the kinds announced, and the ids,
or :all when more than 100 were announced (the page then reads its
whole view again).
Callbacks
@callback refresh(Phoenix.LiveView.Socket.t(), changes()) :: Phoenix.LiveView.Socket.t()
Reads again what the page shows, after changes.