Yex.Doc (y_ex v0.8.0)
View SourceDocument module.
Important
It is not recommended to perform operations on a single document from multiple processes simultaneously. If blocked by a transaction, the Beam scheduler threads may potentially deadlock. This limitation is due to the underlying yrs and beam specifications and may be resolved in the future.
Summary
Functions
Stop monitoring document updates.
Get or insert the array type.
Get or insert the map type.
Get or insert the text type.
Get or insert the xml fragment type.
Monitor document updates. You can pass metadata as an option. This value is passed as the fourth element of the message.If omitted, it will be passed as a structure of Doc itself.
Create a new document.
Executes the given block in the document's worker process. If the current process is already the worker process, executes directly. Otherwise, delegates execution to the worker process via GenServer.call.
Start a transaction.
Create a new document with options.
Types
Functions
Stop monitoring document updates.
@spec get_array(t(), String.t()) :: Yex.Array.t()
Get or insert the array type.
Get or insert the map type.
@spec get_text(t(), String.t()) :: Yex.Text.t()
Get or insert the text type.
Get or insert the xml fragment type.
Monitor document updates. You can pass metadata as an option. This value is passed as the fourth element of the message.If omitted, it will be passed as a structure of Doc itself.
Create a new document.
worker_pid: If there is a possibility of passing the created document to another process, please specify the process responsible for operating the document. This process needs to handle the GenServer handle_call messages as follows:
@impl true
def handle_call(
{Yex.Doc, :run, fun},
_from,
state
) do
{:reply, fun.(), state}
end
Executes the given block in the document's worker process. If the current process is already the worker process, executes directly. Otherwise, delegates execution to the worker process via GenServer.call.
Raises if worker_pid is not set.
Start a transaction.
Examples
iex> doc = Doc.new()
iex> text = Doc.get_text(doc, "text")
iex> Yex.Doc.monitor_update(doc)
iex> Doc.transaction(doc, fn ->
iex> Text.insert(text, 0, "Hello")
iex> Text.insert(text, 0, "Hello", %{"bold" => true})
iex> end)
iex> assert_receive {:update_v1, _, nil, _}
iex> refute_receive {:update_v1, _, nil, _} # only one update message
@spec with_options(Yex.Doc.Options.t(), pid()) :: t()
Create a new document with options.