Yex.Doc (y_ex v0.10.2)

View Source

Document module.

Cross-Process Operations

When a Doc or SharedType operation is performed from a process different from the process that created the Doc, a message like {Yex.Doc, :run, fun} is sent to the creator process via GenServer.call and the processing is delegated to that process. If you encounter a GenServer.call timeout, this delegation mechanism may be the cause. Make sure the worker process can handle the GenServer call messages properly.

It is recommended to start a GenServer process such as Yex.DocServer when executing operations from other processes.

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.

Create a new document with options.

Types

t()

@type t() :: %Yex.Doc{reference: any(), worker_pid: pid() | nil}

Functions

auto_load(doc)

client_id(doc)

collection_id(doc)

demonitor_update(sub)

@spec demonitor_update(reference()) :: :ok | {:error, term()}

Stop monitoring document updates.

demonitor_update_v1(sub)

demonitor_update_v2(sub)

get_array(doc, name)

@spec get_array(t(), String.t()) :: Yex.Array.t()

Get or insert the array type.

get_map(doc, name)

@spec get_map(t(), String.t()) :: Yex.Map.t()

Get or insert the map type.

get_text(doc, name)

@spec get_text(t(), String.t()) :: Yex.Text.t()

Get or insert the text type.

get_xml_fragment(doc, name)

Get or insert the xml fragment type.

guid(doc)

monitor_subdocs(doc, opt \\ [])

monitor_update(doc, opt \\ [])

@spec monitor_update(
  t(),
  keyword()
) :: {:ok, reference()} | {:error, term()}

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.

monitor_update_v1(doc, opt \\ [])

monitor_update_v2(doc, opt \\ [])

new(worker_pid \\ self())

@spec new(pid()) :: t()

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

offset_kind(doc)

run_in_worker_process(doc, list)

(macro)

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.

should_load(doc)

skip_gc(doc)

transaction(doc, origin \\ nil, exec)

@spec transaction(t(), origin :: term(), (... -> any())) :: term()

Start a transaction.

Raises RuntimeError if a transaction is already in progress.

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

with_options(option, worker_pid \\ self())

@spec with_options(Yex.Doc.Options.t(), pid()) :: t()

Create a new document with options.