Issho.Documents (Issho v0.1.0)

Copy Markdown View Source

The authorities (Issho.Authority) of an Issho instance: one for each open document, found by name on every node of a cluster.

The registry is :global unless the instance's :registry is a module with name(instance, document_id), which returns a GenServer name (a {:via, ...} tuple for Horde or a partitioned registry).

Summary

Functions

Returns a specification to start this module under a supervisor.

The authority of a document, started if it is not running anywhere.

The authority of a document if it is running, on any node, or nil.

Functions

child_spec(arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

open(instance, document_id, identity \\ nil, opts \\ [])

@spec open(atom(), String.t(), Issho.Identity.t() | nil, keyword()) ::
  {:ok, pid()} | {:error, term()}

The authority of a document, started if it is not running anywhere.

What the document is (its spec) comes from the first open: the policy's Issho.Policy.document/2, asked with the identity of whoever opens it, or a :spec given by your server's own code, such as a component that holds the document's initial content and its hook. A browser never gives a spec.

A spec is a map:

  • :engine (required): the document's Issho.Engine or binding.
  • :initial: the initial content, when the store has nothing.
  • :opts: the engine's options.
  • :store: {module, context}, or :none for a document that lasts as long as its authority (Issho.Store.None); the instance's store unless given.
  • :on_transaction: a function of the operations and a context (:document, :author, :revision, and the state :before and :after), run once for each accepted transaction, after the engine and before it is saved and confirmed. It answers :ok (or {:ok, anything}), or {:error, reason} to refuse the transaction: the place to save each change in your own tables.

whereis(instance, document_id)

@spec whereis(atom(), String.t()) :: pid() | nil

The authority of a document if it is running, on any node, or nil.