Reply (Reply v1.1.0)

View Source

Lets you pipe the reply in a Phoenix LiveView. Just write socket |> assigns |> ok() in mount or socket |> assigns |> noreply() in handle_* functions insted of dealing with tuples.

Summary

Functions

Transforms a piped reply into a {:noreply, socket} response tuple.

Transforms a piped reply into a {:ok, socket} response tuple.

Transforms a piped reply with payload into a {:reply, payload, socket} response tuple.

Functions

noreply(socket)

Transforms a piped reply into a {:noreply, socket} response tuple.

Examples

def handle_event("update", %{"id" => id}, socket) do
  socket
  |> assign(:post, Blog.get_post!(id))
  |> noreply()
end

ok(socket)

Transforms a piped reply into a {:ok, socket} response tuple.

Examples

def mount(_params, _session, socket) do
  socket
  |> assign(:posts, Blog.list_posts())
  |> ok()
end

ok(socket, keyword)

reply(socket, payload)

Transforms a piped reply with payload into a {:reply, payload, socket} response tuple.

Examples

def handle_event("update", %{"id" => id}, socket) do
  {:ok, post} = Blog.get_post!(id)

  socket
  |> assign(:post, post)
  |> reply(%{last_update: post.updated_at})
end