Skip to content

Commit

Permalink
Remove enum protocol for now
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismccord committed Sep 20, 2023
1 parent f4ed083 commit 9a25cbf
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 98 deletions.
33 changes: 0 additions & 33 deletions lib/phoenix_live_view/async_result.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
25 changes: 0 additions & 25 deletions test/phoenix_live_view/async_result_test.exs

This file was deleted.

16 changes: 0 additions & 16 deletions test/phoenix_live_view/integrations/assign_async_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =~ "<div>1</div><div>2</div><div>3</div>"
end

test "trapping exits", %{conn: conn} do
Process.register(self(), :trap_exit_test)
{:ok, lv, _html} = live(conn, "/assign_async?test=trap_exit")
Expand Down Expand Up @@ -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 =~ "<div>4</div><div>5</div><div>6</div>"
end
end
end
25 changes: 1 addition & 24 deletions test/support/live_views/general.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -354,10 +354,6 @@ defmodule Phoenix.LiveViewTest.AssignAsyncLive do
<div :if={@data.ok? && @data.result == nil}>no data found</div>
<div :if={@data.ok? && @data.result}>data: <%= inspect(@data.result) %></div>
<div :if={@data.failed}><%= inspect(@data.failed) %></div>
<%= if @enum do %>
<div :for={i <- @data}><%= i %></div>
<% end %>
"""
end

Expand Down Expand Up @@ -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
Expand All @@ -446,9 +437,6 @@ defmodule Phoenix.LiveViewTest.AssignAsyncLive.LC do
def render(assigns) do
~H"""
<div>
<%= if @enum do %>
<div :for={i <- @lc_data}><%= i %></div>
<% end %>
<.async_result :let={data} assign={@lc_data}>
<:loading>lc_data loading...</:loading>
<:failed :let={{kind, reason}}><%= kind %>: <%= inspect(reason) %></:failed>
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9a25cbf

Please sign in to comment.