Operations and Diff

A transaction has associated with it a set of operations, inverseOperations and a diff.

The changeEvent contains those 3 properties while the normalizeEvent contains only the diff:

doc.onNormalize(({ diff }) => {
  console.log("normalize", diff);
});

doc.onChange(({ operations, inverseOperations, diff }) => {
  console.log("change", operations, inverseOperations, diff);
});

You can expand the rows in the following table to see a description of these objects:

Prop

Type

These three objects are cleared or reset at the end of the change stage. Until then, getPrev will return the value of the state that the node had at the beginning of the transaction.

Operations

An alternative way to describe a document or the change of a document to a later state is as a set of operations.

In OT mode, the set of operations must be ordered. For all clients to converge on the same document, they must apply the same operations in the same order. Therefore, a central server is required as the source of truth.

In CRDT mode, the operations will be commutative. This means that operations can be applied in any order or multiple times, and the resulting document will be the same. At the cost of higher metadata, CRDTs are suitable for P2P.