Skip to content

Commit

Permalink
Applying suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
cristineguadelupe committed Sep 4, 2023
1 parent e323c82 commit 8d537af
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
27 changes: 11 additions & 16 deletions lib/kino/remote_cell.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,11 @@ defmodule Kino.RemoteCell do
end

@impl true
def to_source(attrs) do
attrs |> to_quoted() |> Kino.SmartCell.quoted_to_string()
end

defp to_quoted(%{"node" => ""}), do: build_empty()
defp to_quoted(%{"cookie" => ""}), do: build_empty()
defp to_quoted(%{"code" => ""}), do: build_empty()
def to_source(%{"node" => ""}), do: ""
def to_source(%{"cookie" => ""}), do: ""
def to_source(%{"code" => ""}), do: ""

defp to_quoted(%{"code" => code} = attrs) do
def to_source(%{"code" => code} = attrs) do
code = Code.string_to_quoted(code)
to_quoted(attrs, code)
end
Expand All @@ -64,12 +60,16 @@ defmodule Kino.RemoteCell do
Node.connect(node)
unquote(call)
end
|> Kino.SmartCell.quoted_to_string()
end

defp to_quoted(%{"code" => code}, {:error, _reason}) do
quote do
Code.string_to_quoted!(unquote(code))
end
"# Invalid code for RPC, reproducing the error below\n" <>
Kino.SmartCell.quoted_to_string(
quote do
Code.string_to_quoted!(unquote(code))
end
)
end

defp build_call(code) do
Expand All @@ -85,9 +85,4 @@ defmodule Kino.RemoteCell do
unquote({String.to_atom(var), [], nil}) = unquote(call)
end
end

defp build_empty() do
quote do
end
end
end
1 change: 1 addition & 0 deletions test/kino/remote_cell.exs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ defmodule Kino.RemoteCellTest do
attrs = %{@fields | "code" => "1 + "}

assert RemoteCell.to_source(attrs) == """
# Invalid code for RPC, reproducing the error below
Code.string_to_quoted!("1 + ")\
"""
end
Expand Down

0 comments on commit 8d537af

Please sign in to comment.