I thought these 2 implementations are the same.
case Customers.update_customer(customer, params) do
{:ok, new_customer} ->
{:noreply,
socket
|> assign(:customer_form, to_form(Customers.change_customer(%Customer{})))
|> assign(
:customers_list,
Enum.map(socket.assigns.customers_list, fn c ->
if c.id == id do
new_customer
else
c
end
end)
)
|> put_flash(:info, "Customer details updated!")}
{:error, %Ecto.Changeset{} = changeset} ->
{:noreply,
socket
|> assign(:customer_form, to_form(changeset))
|> put_flash(:error, "failed to update customer details")}
end
case Customers.update_customer(customer, params) do
{:ok, new_customer} ->
socket
|> assign(:customer_form, to_form(Customers.change_customer(%Customer{})))
|> assign(
:customers_list,
Enum.map(socket.assigns.customers_list, fn c ->
if c.id == id do
new_customer
else
c
end
end)
)
|> put_flash(:info, "Customer details updated!")
{:noreply, socket}
{:error, %Ecto.Changeset{} = changeset} ->
{:noreply,
socket
|> assign(:customer_form, to_form(changeset))
|> put_flash(:error, "failed to update customer details")}
end
In the above example, I pipe the assigns directly in the {:noreply, socket |> …}. This works perfectly and my socket is updated. HOWEVER, when I place the piping outside of the {:noreply, socket} tuple, the socket does not update. Why is that so?