mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-11-13 23:59:47 +08:00
Compute cell snapshots when an existing notebook is given (#666)
This commit is contained in:
parent
cd79e07f2b
commit
2694007c0e
2 changed files with 34 additions and 10 deletions
|
|
@ -155,7 +155,7 @@ defmodule Livebook.Session.Data do
|
||||||
"""
|
"""
|
||||||
@spec new(Notebook.t()) :: t()
|
@spec new(Notebook.t()) :: t()
|
||||||
def new(notebook \\ Notebook.new()) do
|
def new(notebook \\ Notebook.new()) do
|
||||||
%__MODULE__{
|
data = %__MODULE__{
|
||||||
notebook: notebook,
|
notebook: notebook,
|
||||||
origin: nil,
|
origin: nil,
|
||||||
file: nil,
|
file: nil,
|
||||||
|
|
@ -167,6 +167,11 @@ defmodule Livebook.Session.Data do
|
||||||
clients_map: %{},
|
clients_map: %{},
|
||||||
users_map: %{}
|
users_map: %{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data
|
||||||
|
|> with_actions()
|
||||||
|
|> compute_snapshots()
|
||||||
|
|> elem(0)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp initial_section_infos(notebook) do
|
defp initial_section_infos(notebook) do
|
||||||
|
|
@ -1235,7 +1240,7 @@ defmodule Livebook.Session.Data do
|
||||||
number_of_evaluations: 0,
|
number_of_evaluations: 0,
|
||||||
bound_to_input_ids: MapSet.new(),
|
bound_to_input_ids: MapSet.new(),
|
||||||
bound_input_readings: [],
|
bound_input_readings: [],
|
||||||
snapshot: {:initial, :initial},
|
snapshot: {nil, nil},
|
||||||
evaluation_snapshot: nil
|
evaluation_snapshot: nil
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
@ -1411,7 +1416,7 @@ defmodule Livebook.Session.Data do
|
||||||
|> input_readings_snapshot()
|
|> input_readings_snapshot()
|
||||||
end
|
end
|
||||||
|
|
||||||
defp input_readings_snapshot([]), do: :initial
|
defp input_readings_snapshot([]), do: :empty
|
||||||
|
|
||||||
defp input_readings_snapshot(name_value_pairs) do
|
defp input_readings_snapshot(name_value_pairs) do
|
||||||
name_value_pairs |> Enum.sort() |> :erlang.phash2()
|
name_value_pairs |> Enum.sort() |> :erlang.phash2()
|
||||||
|
|
|
||||||
|
|
@ -20,15 +20,34 @@ defmodule Livebook.Session.DataTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "called with a notebook, sets default cell and section infos" do
|
test "called with a notebook, sets default cell and section infos" do
|
||||||
cell = Notebook.Cell.new(:elixir)
|
notebook = %{
|
||||||
section = %{Notebook.Section.new() | cells: [cell]}
|
Notebook.new()
|
||||||
notebook = %{Notebook.new() | sections: [section]}
|
| sections: [
|
||||||
|
%{
|
||||||
|
Notebook.Section.new()
|
||||||
|
| id: "s1",
|
||||||
|
cells: [%{Notebook.Cell.new(:elixir) | id: "c1"}]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
cell_id = cell.id
|
assert %{cell_infos: %{"c1" => %{}}, section_infos: %{"s1" => %{}}} = Data.new(notebook)
|
||||||
section_id = section.id
|
end
|
||||||
|
|
||||||
assert %{cell_infos: %{^cell_id => %{}}, section_infos: %{^section_id => %{}}} =
|
test "called with a notebook, computes cell snapshots" do
|
||||||
Data.new(notebook)
|
notebook = %{
|
||||||
|
Notebook.new()
|
||||||
|
| sections: [
|
||||||
|
%{
|
||||||
|
Notebook.Section.new()
|
||||||
|
| id: "s1",
|
||||||
|
cells: [%{Notebook.Cell.new(:elixir) | id: "c1"}]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
assert %{cell_infos: %{"c1" => %{snapshot: snapshot}}} = Data.new(notebook)
|
||||||
|
assert snapshot != {nil, nil}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue