Skip to content

Commit

Permalink
Fix dbg pipeline when result renders as Kino.JS.Live (#453)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonatanklosko authored Jul 3, 2024
1 parent bca0dfb commit e34687e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/kino/debug/pipeline.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ defmodule Kino.Debug.Pipeline do

%{id: last_id} = List.last(items)

send(self(), :update_result_frame)

{:ok,
ctx
|> assign(
Expand All @@ -44,8 +46,7 @@ defmodule Kino.Debug.Pipeline do
error: nil,
call_count: 1,
changed?: false
)
|> update_result_frame()}
)}
end

@impl true
Expand Down Expand Up @@ -127,6 +128,10 @@ defmodule Kino.Debug.Pipeline do
{:noreply, ctx}
end

def handle_info(:update_result_frame, ctx) do
{:noreply, update_result_frame(ctx)}
end

defp handle_items_change(ctx, items) do
id =
ctx.assigns.items
Expand Down
17 changes: 17 additions & 0 deletions test/kino/debug_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,23 @@ defmodule Kino.Debug.Test do
assert dbg_line == __ENV__.line - 28
end

test "initial render with result requiring Kino.start_child/1" do
# Rendering %UserAsTable{} creates a Kino.JS.Live
call_dbg(
%UserAsTable{id: 1}
|> Map.replace!(:id, 2)
|> Map.replace!(:id, 3)
)

{_kino, _output, frame_ref} = assert_dbg_pipeline_render()

assert_output(%{
type: :frame_update,
ref: ^frame_ref,
update: {:replace, [%{type: :js}]}
})
end

test "updates result when a pipeline step is disabled" do
call_dbg(
1..5
Expand Down
9 changes: 9 additions & 0 deletions test/support/test_modules/user_as_table.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
defmodule UserAsTable do
defstruct [:id]

defimpl Kino.Render do
def to_livebook(user) do
Kino.DataTable.new([%{id: user.id}]) |> Kino.Render.to_livebook()
end
end
end

0 comments on commit e34687e

Please sign in to comment.