true if the handle is in one of the given states.
true if the document has been marked as deleted.
true if the document has not been deleted. Repo only hands out
handles that already have data, so this is true from construction
unless delete() is called.
true if the document is currently unavailable.
true if the document has been unloaded.
StaticprefixedOur documentId in Automerge URL form.
Optionalcontext: anySends an arbitrary ephemeral message out to all reachable peers who would receive sync messages from you. It has no guarantee of delivery, and is not persisted to the underlying automerge doc in any way. Messages will have a sending PeerId but this is not a useful user identifier (a user could have multiple tabs open and would appear as multiple PeerIds). Every message source must have a unique PeerId.
All changes to an Automerge document should be made through this method. Inside the callback, the document should be treated as mutable: all edits will be recorded using a Proxy and translated into operations as part of a single recorded "change".
Note that assignment via ES6 spread operators will result in replacing the object
instead of mutating it which will prevent clean merges. This may be what you want, but
doc.foo = { ...doc.foo, bar: "baz" } is not equivalent to doc.foo.bar = "baz".
Local changes will be stored (by the StorageSubsystem) and synchronized (by the DocSynchronizer) to any peers you are sharing it with.
Called by the repo when the document is deleted.
Calls each of the listeners registered for a given event.
Return an array listing the events for which the emitter has registered listeners.
Returns the latest known heads for the given peer's storageId, or undefined if we have not received sync info from that peer.
Use DocHandle.getSyncInfo instead. Will be removed in the next major.
Returns the current "heads" of the document, akin to a git commit. This precisely defines the state of a document.
the current document's heads, or undefined if the document is not ready
Returns an array of all past "heads" for the document in topological order.
UrlHeads[] - The individual heads for every change in the document. Each item is a tagged string[1].
A point-in-time in an automerge document is an array of heads since there may be concurrent edits. This API just returns a topologically sorted history of all edits so every previous entry will be (in some sense) before later ones, but the set of all possible history views would be quite large under concurrency (every thing in each branch against each other). There might be a clever way to think about this, but we haven't found it yet, so for now at least we present a single traversable view which excludes concurrency.
Check if the document can be change()ed. Currently, documents can be edited unless we are viewing a particular point in time.
boolean indicating whether changes are possible
Return the number of listeners listening to a given event.
Return the listeners registered for a given event.
Merges another document into this document. Any peers we are sharing changes with will be notified of the changes resulting from the merge.
the merged document.
Optionalfn: (Optionalcontext: anyOptionalonce: booleanAdd a listener for a given event.
Optionalcontext: anyAdd a one-time listener for a given event.
Optionalcontext: anyExperimentalCreate a ref to a location in this document.
Returns the same ref instance for the same path, ensuring referential equality.
This API is experimental and may change in future versions.
Called by the repo to reuse an unloaded handle.
Remove all listeners, or those of the specified event.
Optionalevent: keyof DocHandleEvents<T>Remove the listeners of a given event.
Optionalfn: (Optionalcontext: anyOptionalonce: booleanCalled by the repo to free memory used by the document.
Returns a promise that resolves when the handle is in one of the given
states (default ["ready"]).
OptionalawaitStates: HandleState[]
A DocHandle is a wrapper around a single Automerge document that lets us listen for changes and notify the network and storage of new changes.
Remarks
A
DocHandlerepresents a document which is being managed by a Repo. You shouldn't ever instantiate this yourself. To obtainDocHandleuse Repo.find or Repo.create.To modify the underlying document use either DocHandle.change or DocHandle.changeAt. These methods will notify the
Repothat some change has occured and theRepowill save any new changes to the attached StorageAdapter and send sync messages to connected peers.