WardrikWeb. Follow
(wardrik_web v0.1.0-rc.1)
Copy Markdown
Keeps a LiveView up to date with a streamed operation.
When events arrive, it reloads the view. It reloads at most once every 250 ms.
def mount(_params, _session, socket),
do: {:ok, socket |> load() |> WardrikWeb.Follow.start("events.list", %{})}
def handle_info({WardrikWeb.Follow, _message} = message, socket),
do: {:noreply, WardrikWeb.Follow.handle(message, socket, &load/1)}- The stream starts only once the LiveView is connected.
- The stream runs in a task linked to the LiveView. When one exits, the other exits too.
@liveistruewhile the stream is open. When the stream fails or ends,@liveisfalseand@stoppedgives the reason.
Summary
Functions
Streams events for every agent the scope can see, using events.list.
Handles a message sent by the stream.
Starts streaming operation id with input, in the socket's scope.
Functions
@spec agents(Phoenix.LiveView.Socket.t()) :: Phoenix.LiveView.Socket.t()
Streams events for every agent the scope can see, using events.list.
Agents created later are included the next time the view mounts.
@spec handle( {module(), term()}, Phoenix.LiveView.Socket.t(), (term() -> term()), keyword() ) :: Phoenix.LiveView.Socket.t()
Handles a message sent by the stream.
It calls reload with the socket after events arrive. If you pass :on_event, it calls it
with each event.
@spec start(Phoenix.LiveView.Socket.t(), String.t(), map()) :: Phoenix.LiveView.Socket.t()
Starts streaming operation id with input, in the socket's scope.