mirror of
https://github.com/livebook-dev/livebook.git
synced 2024-12-29 19:20:46 +08:00
Don't copy outputs when converting smart cell to code (#2348)
This commit is contained in:
parent
072b8eef82
commit
a5dd74061c
2 changed files with 4 additions and 37 deletions
|
@ -1142,14 +1142,12 @@ defmodule Livebook.Session do
|
|||
Notebook.fetch_cell_and_section(state.data.notebook, cell_id) do
|
||||
index = Enum.find_index(section.cells, &(&1 == cell))
|
||||
chunks = cell.chunks || [{0, byte_size(cell.source)}]
|
||||
chunk_count = length(chunks)
|
||||
|
||||
state =
|
||||
for {{offset, size}, chunk_idx} <- Enum.with_index(chunks), reduce: state do
|
||||
state ->
|
||||
outputs = if(chunk_idx == chunk_count - 1, do: cell.outputs, else: [])
|
||||
source = binary_part(cell.source, offset, size)
|
||||
attrs = %{source: source, outputs: outputs}
|
||||
attrs = %{source: source}
|
||||
cell_idx = index + chunk_idx
|
||||
cell_id = Utils.random_id()
|
||||
|
||||
|
|
|
@ -178,8 +178,7 @@ defmodule Livebook.SessionTest do
|
|||
assert_receive {:operation, {:delete_cell, _client_id, ^cell_id}}
|
||||
|
||||
assert_receive {:operation,
|
||||
{:insert_cell, _client_id, ^section_id, 0, :code, _id,
|
||||
%{source: "content", outputs: []}}}
|
||||
{:insert_cell, _client_id, ^section_id, 0, :code, _id, %{source: "content"}}}
|
||||
end
|
||||
|
||||
test "inserts multiple cells when the smart cell has explicit chunks" do
|
||||
|
@ -206,40 +205,10 @@ defmodule Livebook.SessionTest do
|
|||
assert_receive {:operation, {:delete_cell, _client_id, ^cell_id}}
|
||||
|
||||
assert_receive {:operation,
|
||||
{:insert_cell, _client_id, ^section_id, 0, :code, _id,
|
||||
%{source: "chunk 1", outputs: []}}}
|
||||
{:insert_cell, _client_id, ^section_id, 0, :code, _id, %{source: "chunk 1"}}}
|
||||
|
||||
assert_receive {:operation,
|
||||
{:insert_cell, _client_id, ^section_id, 1, :code, _id,
|
||||
%{source: "chunk 2", outputs: [{1, terminal_text("Hello")}]}}}
|
||||
end
|
||||
|
||||
test "doesn't garbage collect input values" do
|
||||
input = %{
|
||||
type: :input,
|
||||
ref: "ref",
|
||||
id: "input1",
|
||||
destination: :noop,
|
||||
attrs: %{type: :text, default: "hey", label: "Name", debounce: :blur}
|
||||
}
|
||||
|
||||
smart_cell = %{
|
||||
Notebook.Cell.new(:smart)
|
||||
| kind: "text",
|
||||
source: "content",
|
||||
outputs: [{1, input}]
|
||||
}
|
||||
|
||||
section = %{Notebook.Section.new() | cells: [smart_cell]}
|
||||
notebook = %{Notebook.new() | sections: [section]}
|
||||
|
||||
session = start_session(notebook: notebook)
|
||||
|
||||
Session.subscribe(session.id)
|
||||
|
||||
Session.convert_smart_cell(session.pid, smart_cell.id)
|
||||
|
||||
assert %{input_infos: %{"input1" => %{value: "hey"}}} = Session.get_data(session.pid)
|
||||
{:insert_cell, _client_id, ^section_id, 1, :code, _id, %{source: "chunk 2"}}}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue