Skip to content

Commit

Permalink
FC
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismccord committed Aug 7, 2023
1 parent 44c2ad3 commit 5226415
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/phoenix_live_view/async_assign.ex
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ defmodule Phoenix.LiveView.AsyncAssign do

slot :empty,
doc:
"rendered when the result is loaded and is either nil or an empty enumerable. Receives the result as a :let."
"rendered when the result is loaded and is either nil or an empty list. Receives the result as a :let."

slot :error,
doc:
Expand All @@ -106,7 +106,7 @@ defmodule Phoenix.LiveView.AsyncAssign do
def async_result(assigns) do
case assigns.assign do
%AsyncAssign{result: result, loading?: false, error: nil, canceled?: false} ->
if assigns.empty != [] && (is_nil(result) or Enum.empty?(result)) do
if assigns.empty != [] && result in [nil, []] do
~H|<%= render_slot(@empty, @assign.result) %>|
else
~H|<%= render_slot(@inner_block, @assign.result) %>|
Expand Down
14 changes: 8 additions & 6 deletions test/support/live_views/general.ex
Original file line number Diff line number Diff line change
Expand Up @@ -430,15 +430,17 @@ defmodule Phoenix.LiveViewTest.AsyncLive.LC do
def render(assigns) do
~H"""
<div>
<div :if={@async.lc_data.loading?}>lc_data loading...</div>
<div :if={@async.lc_data.canceled?}>lc_data canceled</div>
<div :if={[email protected]_data.loading? && @async.lc_data.result == nil}>no lc_data found</div>
<div :if={[email protected]_data.loading? && @async.lc_data.result}>lc_data: <%= inspect(@async.lc_data.result) %></div>
<div :if={err = @async.lc_data.error}>error: <%= inspect(err) %></div>
<%= if @enum do %>
<div :for={i <- @async.lc_data}><%= i %></div>
<% end %>
<.async_result :let={data} assign={@async.lc_data}>
<:loading>lc_data loading...</:loading>
<:canceled>lc_data canceled</:canceled>
<:empty :let={_res}>no lc_data found</:empty>
<:error :let={err}>error: <%= inspect(err) %></:error>
lc_data: <%= inspect(data) %>
</.async_result>
</div>
"""
end
Expand Down

0 comments on commit 5226415

Please sign in to comment.