From 9a25cbfa183165b2fe30e5c0b8e7b151f4d8477d Mon Sep 17 00:00:00 2001 From: Chris McCord Date: Fri, 1 Sep 2023 13:13:44 -0400 Subject: [PATCH] Remove enum protocol for now --- lib/phoenix_live_view/async_result.ex | 33 ------------------- test/phoenix_live_view/async_result_test.exs | 25 -------------- .../integrations/assign_async_test.exs | 16 --------- test/support/live_views/general.ex | 25 +------------- 4 files changed, 1 insertion(+), 98 deletions(-) delete mode 100644 test/phoenix_live_view/async_result_test.exs diff --git a/lib/phoenix_live_view/async_result.ex b/lib/phoenix_live_view/async_result.ex index 26bc31fa5f..0989c05ffb 100644 --- a/lib/phoenix_live_view/async_result.ex +++ b/lib/phoenix_live_view/async_result.ex @@ -76,37 +76,4 @@ defmodule Phoenix.LiveView.AsyncResult do def ok(%AsyncResult{} = result, value) do %AsyncResult{result | failed: nil, loading: nil, ok?: true, result: value} end - - defimpl Enumerable, for: Phoenix.LiveView.AsyncResult do - alias Phoenix.LiveView.AsyncResult - - def count(%AsyncResult{result: result, ok?: true}), - do: Enumerable.count(result) - - def count(%AsyncResult{}), do: 0 - - def member?(%AsyncResult{result: result, ok?: true}, item) do - Enumerable.member?(result, item) - end - - def member?(%AsyncResult{}, _item), do: false - - def reduce( - %AsyncResult{result: result, ok?: true}, - acc, - fun - ) do - Enumerable.reduce(result, acc, fun) - end - - def reduce(%AsyncResult{}, {_, acc}, _fun), do: {:done, acc} - - def slice(%AsyncResult{result: result, ok?: true}) do - Enumerable.slice(result) - end - - def slice(%AsyncResult{}) do - fn _start, _length, _step -> [] end - end - end end diff --git a/test/phoenix_live_view/async_result_test.exs b/test/phoenix_live_view/async_result_test.exs deleted file mode 100644 index e53a0f4c9c..0000000000 --- a/test/phoenix_live_view/async_result_test.exs +++ /dev/null @@ -1,25 +0,0 @@ -defmodule Phoenix.LiveView.AsyncResultTest do - use ExUnit.Case, async: true - - alias Phoenix.LiveView.AsyncResult - - test "ok" do - async = AsyncResult.loading() - assert Enum.sum(AsyncResult.ok(async, [1, 1, 1])) == 3 - assert Enum.count(AsyncResult.ok(async, [1, 2, 3])) == 3 - assert Enum.map(AsyncResult.ok(async, [1, 2, 3]), &(&1 * 2)) == [2, 4, 6] - end - - test "not ok" do - async = AsyncResult.loading() - - # loading - assert Enum.sum(async) == 0 - assert Enum.map(async, & &1) == [] - - # failed - failed = AsyncResult.failed(async, {:exit, :boom}) - assert Enum.sum(failed) == 0 - assert Enum.map(failed, & &1) == [] - end -end diff --git a/test/phoenix_live_view/integrations/assign_async_test.exs b/test/phoenix_live_view/integrations/assign_async_test.exs index c7c8e12d28..fb84091d6a 100644 --- a/test/phoenix_live_view/integrations/assign_async_test.exs +++ b/test/phoenix_live_view/integrations/assign_async_test.exs @@ -76,14 +76,6 @@ defmodule Phoenix.LiveView.AssignAsyncTest do assert render_async(lv, 200) =~ "data: 123" end - test "enum", %{conn: conn} do - {:ok, lv, _html} = live(conn, "/assign_async?test=enum") - - html = render_async(lv, 200) - assert html =~ "data: [1, 2, 3]" - assert html =~ "
1
2
3
" - end - test "trapping exits", %{conn: conn} do Process.register(self(), :trap_exit_test) {:ok, lv, _html} = live(conn, "/assign_async?test=trap_exit") @@ -165,13 +157,5 @@ defmodule Phoenix.LiveView.AssignAsyncTest do assert render(lv) =~ "lc_data loading..." assert render_async(lv, 200) =~ "lc_data: 123" end - - test "enum", %{conn: conn} do - {:ok, lv, _html} = live(conn, "/assign_async?test=lc_enum") - - html = render_async(lv, 200) - assert html =~ "lc_data: [4, 5, 6]" - assert html =~ "
4
5
6
" - end end end diff --git a/test/support/live_views/general.ex b/test/support/live_views/general.ex index 6029eebb5a..e301e04ebb 100644 --- a/test/support/live_views/general.ex +++ b/test/support/live_views/general.ex @@ -343,7 +343,7 @@ defmodule Phoenix.LiveViewTest.AssignAsyncLive do on_mount({__MODULE__, :defaults}) def on_mount(:defaults, _params, _session, socket) do - {:cont, assign(socket, enum: false, lc: false)} + {:cont, assign(socket, lc: false)} end def render(assigns) do @@ -354,10 +354,6 @@ defmodule Phoenix.LiveViewTest.AssignAsyncLive do
no data found
data: <%= inspect(@data.result) %>
<%= inspect(@data.failed) %>
- - <%= if @enum do %> -
<%= i %>
- <% end %> """ end @@ -415,11 +411,6 @@ defmodule Phoenix.LiveViewTest.AssignAsyncLive do end)} end - def mount(%{"test" => "enum"}, _session, socket) do - {:ok, - socket |> assign(enum: true) |> assign_async(:data, fn -> {:ok, %{data: [1, 2, 3]}} end)} - end - def handle_info(:boom, _socket), do: exit(:boom) def handle_info(:cancel, socket) do @@ -446,9 +437,6 @@ defmodule Phoenix.LiveViewTest.AssignAsyncLive.LC do def render(assigns) do ~H"""
- <%= if @enum do %> -
<%= i %>
- <% end %> <.async_result :let={data} assign={@lc_data}> <:loading>lc_data loading... <:failed :let={{kind, reason}}><%= kind %>: <%= inspect(reason) %> @@ -459,10 +447,6 @@ defmodule Phoenix.LiveViewTest.AssignAsyncLive.LC do """ end - def mount(socket) do - {:ok, assign(socket, enum: false)} - end - def update(%{test: "bad_return"}, socket) do {:ok, assign_async(socket, :lc_data, fn -> 123 end)} end @@ -499,13 +483,6 @@ defmodule Phoenix.LiveViewTest.AssignAsyncLive.LC do end)} end - def update(%{test: "enum"}, socket) do - {:ok, - socket - |> assign(enum: true) - |> assign_async(:lc_data, fn -> {:ok, %{lc_data: [4, 5, 6]}} end)} - end - def update(%{action: :boom}, _socket), do: exit(:boom) def update(%{action: :cancel}, socket) do