livebook/lib/live_book/notebook/cell.ex
Jonatan Kłosko 00b06f6e7a
Define session data structure and implement several operations (#6)
* Define session data structure and some operations

* Make code evaluation request async, so that we don't need an intermediary process

* Simplify id typespecs

* Make operation application composable

* Keep a separate evaluation queue per section and actually support concurrent evaluation

* Small fixes

* Validate queued cell type and set evaluation timestamp

* Apply review suggestions

* Add tests

* Store evaluating_cell_id instead of section status

* Add dynamic supervisor for managing evaluator processes

* Some fixes

* Refactor operation application

* Upon cell deletion mark dependent cells as stale
2021-01-13 14:39:04 +01:00

39 lines
904 B
Elixir

defmodule LiveBook.Notebook.Cell do
@moduledoc """
Data structure representing a single cell in a notebook.
A cell is the smallest unit of work in a notebook.
It primarly consists of text content that the user can edit
and may potentially produce some output (e.g. during code evaluation).
"""
defstruct [:id, :type, :source, :outputs, :metadata]
alias LiveBook.Utils
@type id :: Utils.id()
@type type :: :markdown | :elixir
@type t :: %__MODULE__{
id: id(),
type: type(),
source: String.t(),
# TODO: expand on this
outputs: list(),
metadata: %{atom() => term()}
}
@doc """
Returns an empty cell of the given type.
"""
@spec new(type()) :: t()
def new(type) do
%__MODULE__{
id: Utils.random_id(),
type: type,
source: "",
outputs: [],
metadata: %{}
}
end
end