Alva.Result (Alva v0.1.0)

Copy Markdown View Source

Applies LiveView-specific side effects to the socket based on the result of an Alva.Dispatcher.dispatch/3 call and a requested strategy.

Supported Strategies

  • {:stream_insert, key} - Inserts data into a Phoenix.LiveView stream.
  • {:stream_delete, key} - Deletes data from a Phoenix.LiveView stream.
  • {:assign, key} - Assigns data to the socket.
  • {:push_event, event_name} - Pushes a Phoenix.LiveView event to the client.
  • {:navigate, to} - Navigates to a new LiveView path.
  • {:patch, to} - Patches the current LiveView path.
  • {:custom, module} - Delegates to a custom module's handle_result/2.
  • {:reply, :data} - Default. Returns data without side effects.

Summary

Functions

Transforms the dispatcher result into a LiveView return tuple {:reply, map, socket} and applies the specified side effect to the socket.

Functions

apply(result, socket, opts \\ [])

(since 0.1.0)

Transforms the dispatcher result into a LiveView return tuple {:reply, map, socket} and applies the specified side effect to the socket.

Examples

iex> result = %{ok: true, data: %{id: 1, name: "Test"}}
iex> Alva.Result.apply(result, socket, strategy: {:stream_insert, :students})
{:reply, %{ok: true, data: %{id: 1, name: "Test"}}, socket_with_stream_inserted}