View Source Yex.Sync.SharedDoc.PersistenceBehaviour behaviour (y_ex v0.6.2)
Persistence behavior for SharedDoc
Summary
Callbacks
Invoked to handle SharedDoc bind. Mainly used to read and set the initial values of SharedDoc
Invoked to handle SharedDoc terminate.
Invoked to handle all doc updates.
Callbacks
Invoked to handle SharedDoc bind. Mainly used to read and set the initial values of SharedDoc
Examples save the state to the filesystem
def bind(state, doc_name, doc) do
case File.read("path/to/" <> doc_name, [:read, :binary]) do
{:ok, data} ->
Yex.apply_update(doc, data)
{:error, _} ->
:ok
end
end
Invoked to handle SharedDoc terminate.
This is only executed when SharedDoc exits successfully.
Examples save the state to the filesystem
def unbind(state, doc_name, doc) do
case Yex.encode_state_as_update(doc) do
{:ok, update} ->
File.write!("path/to/" <> doc_name, update, [:write, :binary])
error ->
error
end
:ok
end
@callback update_v1( state :: term(), update :: binary(), doc_name :: String.t(), doc :: Yex.Doc.t() ) :: term()
Invoked to handle all doc updates.