View Source Yex.DocServer behaviour (y_ex v0.7.2)
Define a Yex.DocServer
process.
DocServer
defines a module to handle document update messages by yjs.
Examples
defmodule MyDocServer do
use Yex.DocServer
def init(_arg, state) do
{:ok, state}
end
def handle_update_v1(doc, update, origin, state) do
# Handle document updates from Yjs
# - doc: The current document state
# - update: Binary encoded update
# - origin: Source of the update
{:noreply, state}
end
def handle_awareness_change(awareness, %{removed: removed, added: added, updated: updated}, origin, state) do
# Handle presence/awareness changes
# - awareness: Current awareness state
# - removed/added/updated: Lists of changed client IDs
{:noreply, state}
end
end
Summary
Callbacks
Handle awareness change
Handle regular GenServer call messages.
Handle regular GenServer cast messages.
Handle regular Elixir process messages.
Handle document updates in v1 encoding format.
Initialize the doc process.
Interprets and processes v1 encode message.
Starts a DocServer
process without linking (for use outside of a supervision tree).
Starts a DocServer
process linked to the current process.
Invoked when the document server process is about to exit.
Types
@type option() :: {:doc_option, Yex.Doc.Options.t()} | {:assigns, map()} | {term(), term()}
@type options() :: [option()]
Callbacks
@callback handle_awareness_change( awareness :: Yex.Awareness.t(), update :: %{removed: list(), added: list(), updated: list()}, origin :: binary(), state :: Yex.DocServer.State.t() ) :: {:noreply, Yex.DocServer.State.t()} | {:stop, reason :: term(), Yex.DocServer.State.t()}
Handle awareness change
@callback handle_call( msg :: term(), from :: {pid(), tag :: term()}, state :: Yex.DocServer.State.t() ) :: {:reply, response :: term(), Yex.DocServer.State.t()} | {:noreply, Yex.DocServer.State.t()} | {:stop, reason :: term(), Yex.DocServer.State.t()}
Handle regular GenServer call messages.
@callback handle_cast(msg :: term(), state :: Yex.DocServer.State.t()) :: {:noreply, Yex.DocServer.State.t()} | {:stop, reason :: term(), Yex.DocServer.State.t()}
Handle regular GenServer cast messages.
@callback handle_info(msg :: term(), state :: Yex.DocServer.State.t()) :: {:noreply, Yex.DocServer.State.t()} | {:stop, reason :: term(), Yex.DocServer.State.t()}
Handle regular Elixir process messages.
@callback handle_update_v1( doc :: Yex.Doc.t(), update :: binary(), origin :: binary(), state :: Yex.DocServer.State.t() ) :: {:noreply, Yex.DocServer.State.t()} | {:stop, reason :: term(), Yex.DocServer.State.t()}
Handle document updates in v1 encoding format.
Parameters
- doc: Current document state
- update: Binary encoded update from Yjs
- origin: Source of the update (can be nil for local updates)
- state: Current server state
Returns
{:noreply, state}
to continue with new state{:stop, reason, state}
to stop the server
@callback init(arg :: term(), state :: Yex.DocServer.State.t()) :: {:ok, Yex.DocServer.State.t()} | {:stop, reason :: term()}
Initialize the doc process.
@callback process_message_v1( server :: GenServer.server(), message :: binary(), origin :: binary() ) :: :ok | {:ok, replies :: [binary()]} | {:error, term()}
Interprets and processes v1 encode message.
@callback start( arg :: options(), genserver_option :: GenServer.options() ) :: {:ok, pid()} | {:error, term()}
Starts a DocServer
process without linking (for use outside of a supervision tree).
Returns the same success and error responses as start_link/2
.
@callback start_link( arg :: options(), genserver_option :: GenServer.options() ) :: {:ok, pid()} | {:error, term()}
Starts a DocServer
process linked to the current process.
@callback terminate( reason :: :normal | :shutdown | {:shutdown, :left | :closed | term()}, state :: Yex.DocServer.State.t() ) :: term()
Invoked when the document server process is about to exit.