Documentation
¶
Overview ¶
Package doc owns the Doc and Transaction types — the document container plus its mutation-lifecycle wrapper.
A Doc is the smallest self-contained CRDT replica: it holds a client identifier, a block store of every Item this replica has produced or received, and a single RWMutex that gates concurrent access. Mutations occur inside a Transaction (write) or are observed inside a Transaction (read).
See docs/yrs-port-notes/transaction.md for the per-method contract and the commit lifecycle yrs runs at TransactionMut.Commit; the lifecycle ygo runs is listed on Commit.
Index ¶
- Constants
- Variables
- func Delivering(t *TransactionMut) bool
- func QueueUnderLock(d *Doc, fn func(*TransactionMut))
- type AfterTransactionHandler
- type DeletedRange
- type Doc
- func (d *Doc) Branch(name string) *block.Branch
- func (d *Doc) ClientID() uint64
- func (d *Doc) GC() bool
- func (d *Doc) GUID() string
- func (d *Doc) Load()
- func (d *Doc) OnAfterTransaction(fn AfterTransactionHandler) func()
- func (d *Doc) OnSubdocs(fn func(SubdocsEvent)) func()
- func (d *Doc) OnUpdate(fn UpdateHandler) func()
- func (d *Doc) OnUpdateV2(fn UpdateHandler) func()
- func (d *Doc) PutSubdoc(sub *Doc)
- func (d *Doc) ReadTxn() *Transaction
- func (d *Doc) RemoveSubdoc(guid string)
- func (d *Doc) ShouldLoad() bool
- func (d *Doc) Subdoc(guid string) *Doc
- func (d *Doc) Subdocs() []string
- func (d *Doc) WithRoot(name string, fn func(*block.Branch))
- func (d *Doc) WriteTxn() *TransactionMut
- type Options
- type SubdocsEvent
- type Transaction
- type TransactionMut
- func (t *TransactionMut) AddChangedType(parent *block.Branch, parentSub *string)
- func (t *TransactionMut) AddedSubdoc(item *block.Item)
- func (t *TransactionMut) AfterState() store.StateVector
- func (t *TransactionMut) BeforeState() store.StateVector
- func (t *TransactionMut) ChangedKeys(b *block.Branch) map[string]struct{}
- func (t *TransactionMut) ChangedTypes() []*block.Branch
- func (t *TransactionMut) ClearPositionalTextMarkers()
- func (t *TransactionMut) Commit()
- func (t *TransactionMut) Delete(item *block.Item)
- func (t *TransactionMut) DeleteRange(client, start, end uint64) int
- func (t *TransactionMut) DeletedIDs() []block.ID
- func (t *TransactionMut) DeletedRanges() []DeletedRange
- func (t *TransactionMut) DeletedThisTxn(id block.ID) bool
- func (t *TransactionMut) Doc() *Doc
- func (t *TransactionMut) GetItem(id block.ID) *block.Item
- func (t *TransactionMut) GetOrCreateBranch(name string) *block.Branch
- func (t *TransactionMut) InvalidatePositionalMarkers()
- func (t *TransactionMut) MaterializeCleanEnd(id block.ID) *block.Item
- func (t *TransactionMut) MaterializeCleanStart(id block.ID) *block.Item
- func (t *TransactionMut) OrderSet() *block.OrderSet
- func (t *TransactionMut) PendingState() any
- func (t *TransactionMut) PositionalChanged(b *block.Branch) bool
- func (t *TransactionMut) SetPendingState(s any)
- func (t *TransactionMut) Store() *store.BlockStore
- func (t *TransactionMut) SubdocsAdded() []string
- func (t *TransactionMut) SubdocsLoaded() []string
- func (t *TransactionMut) SubdocsRemoved() []string
- type UpdateHandler
Constants ¶
const MaxClientID uint64 = (1 << 53) - 1
MaxClientID is the upper bound on Doc.ClientID values: 2^53-1, the JavaScript safe-integer range, which bounds every client ID on the wire. Generated IDs are smaller: NewDoc draws them from [1, 2^32-1], as yjs 13 and 14 draw a uint32.
Variables ¶
var FormatCleanupHook func(remote *TransactionMut) func(cleanup *TransactionMut)
FormatCleanupHook, when set, is asked during Commit of a transaction that is not Local, after its after-transaction handlers, whether yjs would clean up formatting after it, and returns the function that does it in the cleanup transaction Commit then opens, or nil. The types package installs it.
var TypeEventHook func(t *TransactionMut)
TypeEventHook, when set, is invoked during Commit (after observers' AfterTransaction handlers, before GC) to dispatch shared-type observe events. The types layer installs it in an init, bridging the doc -> types direction without an import cycle (types imports doc, not the reverse). nil in tests that never register an observer.
var UpdateEncoder func(t *TransactionMut, v2 bool) []byte
UpdateEncoder encodes a committed transaction as the update yjs emits for it ('update' when v2 is false, 'updateV2' when true), or returns nil when the transaction changed nothing. The encoding package installs it in an init: doc cannot import encoding, which imports doc. Every package that exposes OnUpdate imports encoding.
Functions ¶
func Delivering ¶ added in v1.46.0
func Delivering(t *TransactionMut) bool
Delivering reports whether the Commit that runs t (t's own, or its opener's when t is a follow-up) has not yet finished running it and its follow-ups.
func QueueUnderLock ¶ added in v1.24.0
func QueueUnderLock(d *Doc, fn func(*TransactionMut))
QueueUnderLock queues fn to run once with d's write lock held, at the first point where anything could keep or collect an item: when the next write transaction opens, before its body; before each after-transaction handler of the commit in progress; or right before that commit's GC. A plain function rather than a method, so it stays off the public ygo.Doc.
The UndoManager releases what a cleared step kept this way. yjs clear releases at once, so nothing that runs after it can be undone by it: here no transaction body, handler or GC keeps or collects an item between the Clear and its release. Called from an after-transaction handler, the release reaches the GC of that very commit, as in yjs.
Types ¶
type AfterTransactionHandler ¶ added in v0.10.0
type AfterTransactionHandler func(*TransactionMut)
AfterTransactionHandler is invoked once per committed write transaction, after the change-tracking state on TransactionMut has been finalised. The handler runs with the doc's write lock still held; it must not acquire ReadTxn or WriteTxn on the same doc. Heavy or blocking work should be dispatched to a goroutine.
type DeletedRange ¶ added in v1.22.0
DeletedRange is the clock range one Delete tombstoned: Len clocks starting at ID.
type Doc ¶
type Doc struct {
// contains filtered or unexported fields
}
Doc is a single CRDT replica. Construct with NewDoc.
Doc is safe for concurrent access through ReadTxn / WriteTxn — those methods acquire the internal RWMutex appropriately. Direct field access from outside the doc package is not safe.
func NewDoc ¶
func NewDoc() *Doc
NewDoc returns a fresh Doc with default options and a random client identifier in [1, 2^32-1].
func NewDocWithOptions ¶
NewDocWithOptions returns a fresh Doc with the given options. A zero Options{} is equivalent to NewDoc().
func (*Doc) Branch ¶
Branch returns the root branch with the given name, creating it lazily on first access. The returned *block.Branch is the underlying state shared by all types-layer wrappers (Map, Array, Text) constructed against this name on this Doc.
Concurrency: Branch acquires the doc's write lock to insert into the root-branch registry. It MUST be called outside any active Transaction or TransactionMut on this Doc — calling it inside a transaction deadlocks (sync.RWMutex is non-reentrant).
Typical usage:
d := doc.NewDoc()
settingsBranch := d.Branch("settings") // outside any txn
m := types.NewMap(settingsBranch) // wrap once
// later, inside a txn:
txn := d.WriteTxn()
m.Set(txn, "color", "red")
txn.Commit()
func (*Doc) ClientID ¶
ClientID returns the per-replica identifier, the Client field of every ID this replica produces. It changes when an update made elsewhere advances it: another replica uses the same ID, or the document's own history was loaded into a doc with that ID. The doc then draws a new random ID, as yjs does, so its next edits cannot collide; the commit of that update changes it after its observers and after-transaction handlers ran and before its update handlers run. Safe to call from any goroutine.
func (*Doc) GC ¶
GC reports whether garbage collection of fully-observed deleted items will run at transaction commit.
func (*Doc) Load ¶ added in v1.0.0
func (d *Doc) Load()
Load marks this subdocument to be loaded. A provider watching the parent's transactions sees the GUID in SubdocsLoaded and can then fetch and apply the subdocument's own update stream. Idempotent.
func (*Doc) OnAfterTransaction ¶ added in v0.10.0
func (d *Doc) OnAfterTransaction(fn AfterTransactionHandler) func()
OnAfterTransaction registers fn to fire at the end of every future TransactionMut.Commit. Returns an unsubscribe function that removes the handler; calling it more than once is a no-op.
Registration order is preserved; handlers fire in registration order. A handler may register or unsubscribe handlers, itself included, or close an UndoManager, from inside the call; the change applies from the next transaction. Panics in a handler propagate and are NOT caught — they leave the doc write lock held by the panicking goroutine, which is the same behaviour as any other panic during Commit.
func (*Doc) OnSubdocs ¶ added in v1.0.0
func (d *Doc) OnSubdocs(fn func(SubdocsEvent)) func()
OnSubdocs registers fn to fire after any transaction that changed the document's subdocuments. Returns an unsubscribe function. A sync provider uses this to learn which nested documents to start or stop syncing. It fires at the end of the commit, after garbage collection and the update handlers, where yjs emits 'subdocs'; the write lock is still held.
func (*Doc) OnUpdate ¶ added in v1.22.0
func (d *Doc) OnUpdate(fn UpdateHandler) func()
OnUpdate registers fn to receive, after every write transaction that changed the document, a V1 update holding exactly that transaction's changes, and the transaction's Origin. It is the yjs doc.on('update') event: structs created from the transaction's start state on (the first of each client cut at that clock) and the delete set of what the transaction deleted, byte for byte as yjs writes them apart from a pinned case (docs/tech-debt.md, "Remaining update-event divergences": an update whose block depends on another client's block in it integrates in another order, which can change the clocks an undo gives restored items) and the Any values ygo writes differently (objects with several keys, written with sorted keys, and whole-number float64s). An applied update that changed formatted text can be followed by a second update, origin nil, from the format cleanup yjs runs after it (see TransactionMut.Commit). Local edits, applied updates and UndoManager steps all emit one; a transaction that changed nothing emits none.
fn runs at the end of Commit, after observers, after-transaction handlers and garbage collection, with the write lock still held, so updates arrive in commit order even with concurrent writers. Like an after-transaction handler it must not open a transaction on the same doc; send or queue the bytes. It may register or unsubscribe handlers, itself included, or close an UndoManager; a change applies from the next transaction. Returns an unsubscribe function; calling it more than once is a no-op.
func (*Doc) OnUpdateV2 ¶ added in v1.22.0
func (d *Doc) OnUpdateV2(fn UpdateHandler) func()
OnUpdateV2 is OnUpdate with V2 wire bytes, the yjs doc.on('updateV2') event.
func (*Doc) PutSubdoc ¶ added in v0.10.0
PutSubdoc registers an existing Doc as a subdocument under its GUID, so later Subdoc / GetDoc lookups return the same instance. A no-op if a different instance is already registered for that GUID.
func (*Doc) ReadTxn ¶
func (d *Doc) ReadTxn() *Transaction
ReadTxn acquires the doc's read lock and returns a Transaction. The caller MUST call Close (typically via defer) to release the lock.
Multiple read transactions may coexist; they block any concurrent WriteTxn until all read transactions close.
func (*Doc) RemoveSubdoc ¶ added in v1.0.0
RemoveSubdoc drops the in-memory handle for the subdocument with the given GUID from the registry, so later Subdoc / GetDoc lookups no longer return a stale instance. Called when a ContentDoc reference is tombstoned. A no-op if no handle is registered. Safe for concurrent use. CRDT state is unaffected; this only releases the cached handle.
func (*Doc) ShouldLoad ¶ added in v1.0.0
ShouldLoad reports whether this (sub)document is marked to load.
func (*Doc) Subdoc ¶ added in v0.10.0
Subdoc returns the in-memory handle for the subdocument with the given GUID, creating and registering one (GC disabled, matching subdoc semantics) on first access. Safe for concurrent use.
func (*Doc) WithRoot ¶ added in v1.31.0
WithRoot calls fn with the root branch name, created if absent, while it holds the document's write lock, so whatever fn sets on the branch (its type, say) does not race a transaction on another goroutine. Like Branch, it must not be called inside an open transaction on this document; TransactionMut.GetOrCreateBranch is the form for that.
func (*Doc) WriteTxn ¶
func (d *Doc) WriteTxn() *TransactionMut
WriteTxn acquires the doc's write lock and returns a TransactionMut. The caller MUST call Commit (typically via defer) to release the lock and run the commit lifecycle.
WriteTxn blocks until all concurrent ReadTxn / WriteTxn close. Calling WriteTxn while already holding a write lock on this Doc from the same goroutine deadlocks (Go RWMutex is not re-entrant), matching yrs's transact_mut behaviour (transact.rs:255 explicit "this will hang forever" comment).
type Options ¶
type Options struct {
// DisableGC turns OFF garbage collection of fully-observed
// deleted items at transaction commit. Default (false) means GC
// is enabled, matching JS Yjs and yrs. Set to true only if you
// intend to use snapshots; otherwise GC may drop content the
// snapshot needs to materialize.
DisableGC bool
// ClientID overrides the random client identifier. When zero
// (the default), NewDocWithOptions generates one via crypto/rand.
// Pass a fixed value only for deterministic tests. A fixed ID is
// replaced like a random one when an update advances it (see
// Doc.ClientID), loading the document's own history included.
ClientID uint64
// GUID is the document's stable string identity. Subdocuments are
// referenced by GUID on the wire. When empty (the default), a
// random GUID is generated. Two Docs sharing a GUID are treated as
// the same logical (sub)document.
GUID string
}
Options bundles per-Doc settings. The zero value (Options{}) gives the safe defaults that JS Yjs and yrs use: GC enabled, random ClientID. Fields are inverted from their natural English where needed so that Go's zero-value default matches the recommended configuration.
type SubdocsEvent ¶ added in v1.0.0
SubdocsEvent carries the subdocument lifecycle changes observed in a single transaction: the GUIDs added (a ContentDoc surfaced), removed (its reference was tombstoned), and loaded (autoLoad or an explicit Load). Mirrors yjs's "subdocs" event payload.
type Transaction ¶
type Transaction struct {
// contains filtered or unexported fields
}
Transaction is a read-only transaction holding the doc's read lock for its lifetime. Created by Doc.ReadTxn; released by Close.
Mirrors yrs Transaction<'doc>. The lock is held until Close runs; Go has no Drop trait, so Close must be called explicitly. Use a `defer txn.Close()` immediately after acquisition.
A Transaction value must not be retained past its Close call. yrs enforces this with a 'doc lifetime parameter; we document the contract and trust callers (see tech-debt.md).
func (*Transaction) Close ¶
func (t *Transaction) Close()
Close releases the read lock. Safe to call more than once; only the first call unlocks.
func (*Transaction) Doc ¶
func (t *Transaction) Doc() *Doc
Doc returns the Doc this transaction was created from.
func (*Transaction) PendingState ¶
func (t *Transaction) PendingState() any
PendingState returns the opaque pending-update state stored on the doc, read-only. Concrete type is *encoding.Pending; see TransactionMut.PendingState for the rationale.
func (*Transaction) Store ¶
func (t *Transaction) Store() *store.BlockStore
Store returns the doc's BlockStore for read access. Mutations through this pointer would race with WriteTxn writers; do not mutate from within a read transaction.
type TransactionMut ¶
type TransactionMut struct {
// Origin is an opaque caller-supplied value attached to this
// transaction. Mirrors yrs Origin (transaction.rs:1210-1288).
// Visible in observer events to distinguish e.g. local edits
// from updates applied via ApplyUpdate.
Origin any
// Local reports whether the transaction makes changes here rather
// than applying an update made elsewhere, as yjs transaction.local:
// true for WriteTxn, false for the transactions that ApplyUpdate,
// its V2 and origin forms, and the stored-update loaders open. It is
// independent of Origin. A non-local transaction that changes
// formatted text is followed by a format cleanup (see Commit), and
// one that advances the doc's own client clock gives the doc a new
// client ID (Doc.ClientID): a WriteTxn set to false that then edits
// changes the ID at every commit.
Local bool
// contains filtered or unexported fields
}
TransactionMut is a write transaction holding the doc's write lock for its lifetime. Created by Doc.WriteTxn; released by Commit.
Mirrors yrs TransactionMut<'doc>. Accumulates change-tracking state during the transaction; consumes it at Commit time to run the post-commit lifecycle (observers, squash, after-transaction handlers, GC, update events); see Commit.
func OpenFollowUp ¶ added in v1.46.0
func OpenFollowUp(t *TransactionMut) *TransactionMut
OpenFollowUp opens a transaction that the Commit running t runs after t and after the follow-ups opened before it: local, Origin nil, under the lock that Commit holds, as yjs's transact opens one when it is called while transactions are being cleaned up (an event's delta read from an observer, the format cleanup). Its changes apply at once; its lifecycle (observers, handlers, update) comes after t's. It returns nil once that Commit has run every follow-up (Delivering is false): the caller then changes nothing. Call it only from the goroutine running the Commit (its observers and handlers, or those of its follow-ups).
func Opener ¶ added in v1.46.0
func Opener(t *TransactionMut) *TransactionMut
Opener returns the transaction opened by WriteTxn whose Commit runs t as a follow-up (OpenFollowUp), or nil when t is not a follow-up.
func (*TransactionMut) AddChangedType ¶
func (t *TransactionMut) AddChangedType(parent *block.Branch, parentSub *string)
AddChangedType records that a Branch saw user-observable changes during this transaction, tracking the changed map keys (parentSub != nil) and whether positional content changed (parentSub == nil) separately. Drives observer dispatch at Commit. Mirrors yjs transaction.changed (Map<AbstractType, Set<string|null>>).
func (*TransactionMut) AddedSubdoc ¶ added in v1.30.0
func (t *TransactionMut) AddedSubdoc(item *block.Item)
AddedSubdoc implements block.IntegrateContext: it records a subdocument item as it integrates, for trackSubdocs.
func (*TransactionMut) AfterState ¶ added in v0.10.0
func (t *TransactionMut) AfterState() store.StateVector
AfterState returns the per-client clock-head snapshot taken at the start of Commit. Populated only after Commit runs; before Commit the returned map is empty.
func (*TransactionMut) BeforeState ¶ added in v0.10.0
func (t *TransactionMut) BeforeState() store.StateVector
BeforeState returns the per-client clock-head snapshot taken when this transaction acquired the write lock. Read-only; do not mutate the returned map.
Together with AfterState, the per-transaction insertion ranges are `afterState[client] - beforeState[client]` per client.
func (*TransactionMut) ChangedKeys ¶ added in v1.2.0
func (t *TransactionMut) ChangedKeys(b *block.Branch) map[string]struct{}
ChangedKeys returns the set of map keys changed on branch this transaction. Returns nil for a branch with no recorded key changes.
func (*TransactionMut) ChangedTypes ¶
func (t *TransactionMut) ChangedTypes() []*block.Branch
ChangedTypes returns the branches changed this transaction, in the order they were first changed.
func (*TransactionMut) ClearPositionalTextMarkers ¶ added in v1.48.0
func (t *TransactionMut) ClearPositionalTextMarkers()
PositionalChanged reports whether branch saw positional (Array / Text) content changes this transaction. ClearPositionalTextMarkers empties the TextMarkers of every type whose positional content this transaction changed, keeping the items' marker flags, as yjs UndoManager popStackItem empties _searchMarker for each changed type with a positional change after the step.
func (*TransactionMut) Commit ¶
func (t *TransactionMut) Commit()
Commit runs the post-commit lifecycle and releases the write lock. Safe to call more than once; subsequent calls are no-ops.
Lifecycle, in order, all with the write lock held, as yjs cleanupTransactions runs it:
- Snapshot the after-state.
- Shared-type observers (Observe / ObserveDeep), on the layout as the transaction left it.
- Record subdocument changes.
- After-transaction handlers (the UndoManager, sync clients), which may mark deleted items kept. Functions queued with QueueUnderLock run before each handler and once more after the last (and when a write transaction opens).
- GC: free deleted content (unless GC is off or the item is kept) and merge deleted runs.
- Merge this transaction's new blocks into their left neighbours, then the pieces of the items it split (yjs _mergeStructs). Merging after GC means a deleted item this commit collects can no longer merge into a kept neighbour and keep its content.
- Update handlers (OnUpdate, OnUpdateV2), on the final layout.
- Subdocument handlers (OnSubdocs), as yjs emits 'subdocs' last.
A transaction that is not Local and changed a Text or XmlText with formatting is followed, as in yjs (cleanupYTextAfterTransaction), by a cleanup: a local transaction with Origin nil that deletes format markers the remote content made redundant. It is opened and does its deletions between steps 4 and 5, where yjs runs it, while deleted items still hold their content; its own lifecycle (steps 1-8, its update after this transaction's) runs after step 8. Both run under this one lock hold, so no other writer comes between them.
func (*TransactionMut) Delete ¶
func (t *TransactionMut) Delete(item *block.Item)
Delete tombstones an Item and records its ID for inclusion in the transaction's eventual delete-set emission. The Item must already be in the store.
Deleting a shared type's item deletes the items inside it too (deleteTypeContent), as yjs ContentType.delete does.
func (*TransactionMut) DeleteRange ¶ added in v0.10.0
func (t *TransactionMut) DeleteRange(client, start, end uint64) int
DeleteRange tombstones the clock range [start, end) for client, splitting items at the range boundaries so a merged or partially covered item is sliced and only the matching part is tombstoned. Items already deleted are skipped. Clocks the store has not seen are skipped (the range may extend past this replica's state). Returns the number of items newly tombstoned.
This is the split-aware delete shared by the wire delete-set path and the UndoManager. After commit-time squash a single item can span several clocks that belong to distinct logical edits; deleting by range with boundary splitting is what keeps undo and remote deletes correct in the presence of merged blocks.
func (*TransactionMut) DeletedIDs ¶
func (t *TransactionMut) DeletedIDs() []block.ID
DeletedIDs returns the IDs of items tombstoned during this transaction so far. Returned slice aliases internal state; do not mutate. Primarily for tests and the future delete-set emitter.
func (*TransactionMut) DeletedRanges ¶ added in v1.22.0
func (t *TransactionMut) DeletedRanges() []DeletedRange
DeletedRanges returns the exact clock ranges tombstoned during this transaction so far, one per Delete, as they were when deleted. Returned slice aliases internal state; do not mutate.
func (*TransactionMut) DeletedThisTxn ¶ added in v1.2.0
func (t *TransactionMut) DeletedThisTxn(id block.ID) bool
DeletedThisTxn reports whether the clock at id was deleted during this transaction, the deletes(struct) predicate of observer events. Like yjs's isDeleted(transaction.deleteSet, id) it goes by the deleted clock ranges, not by item identity: an item deleted whole and then split by a later integration in the same transaction counts as deleted in every piece.
func (*TransactionMut) Doc ¶
func (t *TransactionMut) Doc() *Doc
Doc returns the Doc this transaction was created from.
func (*TransactionMut) GetItem ¶
func (t *TransactionMut) GetItem(id block.ID) *block.Item
GetItem looks up the Item containing id in the doc's BlockStore. Returns nil for GC cells or unknown IDs.
func (*TransactionMut) GetOrCreateBranch ¶
func (t *TransactionMut) GetOrCreateBranch(name string) *block.Branch
GetOrCreateBranch returns the root branch with the given name from the doc's root-branch registry. Used by block.Repair to resolve ParentNamed references arriving from wire updates.
We do not call Doc.Branch here because Doc.Branch acquires the write lock, which we already hold inside this transaction. Touch the registry directly under the existing lock instead.
func (*TransactionMut) InvalidatePositionalMarkers ¶ added in v1.24.0
func (t *TransactionMut) InvalidatePositionalMarkers()
InvalidatePositionalMarkers drops the search markers of every type whose positional content this transaction changed. The type API keeps its markers in step with its own edits; deletions that do not go through it (an update's delete set, an UndoManager step) leave them pointing at old indices, and yjs resets them there too (_callObserver for a remote transaction, popStackItem for undo).
A type whose markers were reset and whose positions have not changed since is skipped: its markers are as valid as after the reset.
func (*TransactionMut) MaterializeCleanEnd ¶
func (t *TransactionMut) MaterializeCleanEnd(id block.ID) *block.Item
MaterializeCleanEnd returns an Item ending exactly at id.Clock (inclusive), splitting if needed.
func (*TransactionMut) MaterializeCleanStart ¶
func (t *TransactionMut) MaterializeCleanStart(id block.ID) *block.Item
MaterializeCleanStart returns an Item starting exactly at id.Clock, splitting the underlying block in the store if id lands mid-block. Returns nil if id is in a GC cell or unknown.
func (*TransactionMut) OrderSet ¶ added in v1.41.0
func (t *TransactionMut) OrderSet() *block.OrderSet
OrderSet returns the document's set of key orders (block.OrderSet).
func (*TransactionMut) PendingState ¶
func (t *TransactionMut) PendingState() any
PendingState returns the opaque pending-update state stored on the doc. Returns nil when no encoding-layer state has been installed yet. The concrete type is *encoding.Pending; the doc package does not depend on encoding so this stays any-typed at the boundary. Callers (encoding.ApplyUpdate) type-assert.
func (*TransactionMut) PositionalChanged ¶ added in v1.2.0
func (t *TransactionMut) PositionalChanged(b *block.Branch) bool
func (*TransactionMut) SetPendingState ¶
func (t *TransactionMut) SetPendingState(s any)
SetPendingState replaces the opaque pending-update state on the doc. Pass nil to drop pending state entirely (e.g. when the queue drains to empty and the encoding layer wants to release the allocation).
func (*TransactionMut) Store ¶
func (t *TransactionMut) Store() *store.BlockStore
Store returns the doc's BlockStore. Safe to mutate from within this transaction; the write lock prevents concurrent access.
func (*TransactionMut) SubdocsAdded ¶ added in v1.0.0
func (t *TransactionMut) SubdocsAdded() []string
SubdocsAdded returns the GUIDs of subdocuments first surfaced during this transaction (local SetDoc or a decoded remote ContentDoc).
func (*TransactionMut) SubdocsLoaded ¶ added in v1.0.0
func (t *TransactionMut) SubdocsLoaded() []string
SubdocsLoaded returns the GUIDs of subdocuments marked to load during this transaction (autoLoad option or an explicit Load call).
func (*TransactionMut) SubdocsRemoved ¶ added in v1.0.0
func (t *TransactionMut) SubdocsRemoved() []string
SubdocsRemoved returns the GUIDs of subdocuments whose reference was tombstoned during this transaction.
type UpdateHandler ¶ added in v1.22.0
UpdateHandler receives one committed transaction as an update and the transaction's Origin. The bytes are shared by every handler of that transaction; do not modify them.