diff --git a/lib/kino/debug/pipeline.ex b/lib/kino/debug/pipeline.ex index 03935688..c5a44e6e 100644 --- a/lib/kino/debug/pipeline.ex +++ b/lib/kino/debug/pipeline.ex @@ -31,6 +31,8 @@ defmodule Kino.Debug.Pipeline do %{id: last_id} = List.last(items) + send(self(), :update_result_frame) + {:ok, ctx |> assign( @@ -44,8 +46,7 @@ defmodule Kino.Debug.Pipeline do error: nil, call_count: 1, changed?: false - ) - |> update_result_frame()} + )} end @impl true @@ -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 diff --git a/test/kino/debug_test.exs b/test/kino/debug_test.exs index 7eff8414..aa882a48 100644 --- a/test/kino/debug_test.exs +++ b/test/kino/debug_test.exs @@ -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 diff --git a/test/support/test_modules/user_as_table.ex b/test/support/test_modules/user_as_table.ex new file mode 100644 index 00000000..c5eb4231 --- /dev/null +++ b/test/support/test_modules/user_as_table.ex @@ -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