Skip to content

Commit

Permalink
Set to loading if existing
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismccord committed Aug 17, 2023
1 parent 6c8386f commit 412eb78
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/phoenix_live_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ defmodule Phoenix.LiveView do
```heex
<.async_result :let={org} assign={@org}>
<:loading>Loading organization...</:loading>
<:empty>You don't have an organization yet</:error>
<:empty>You don't have an organization yet</:empty>
<:error :let={{_kind, _reason}}>there was an error loading the organization</:error>
<%= org.name %>
<.async_result>
Expand Down
6 changes: 3 additions & 3 deletions lib/phoenix_live_view/async.ex
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ defmodule Phoenix.LiveView.Async do
end

new_assigns =
Enum.flat_map(keys, fn key ->
Enum.map(keys, fn key ->
case socket.assigns do
%{^key => %AsyncResult{ok?: true} = _existing} -> []
%{} -> [{key, AsyncResult.new(keys)}]
%{^key => %AsyncResult{ok?: true} = existing} -> {key, AsyncResult.loading(existing, keys)}
%{} -> {key, AsyncResult.new(keys)}
end
end)

Expand Down

0 comments on commit 412eb78

Please sign in to comment.