Package io.keikai.doc.collab.utils
Class Transaction
java.lang.Object
io.keikai.doc.collab.utils.Transaction
A transaction is created for every change on the Yjs model. It is possible
to bundle changes on the Yjs model in a single transaction to
minimize the number on messages sent and the number of observer calls.
If possible the user of this library should bundle as many changes as
possible. Here is an example to illustrate the advantages of bundling:
-
Constructor Summary
ConstructorsConstructorDescriptionTransaction(Doc doc, Object origin, boolean local) Constructor for the Transaction class. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddChangedTypeToTransaction(Transaction transaction, AbstractType type, String parentSub) Adds a changed type to the transaction.getDoc()getMeta()booleanisLocal()booleanstatic IDnextID(Transaction transaction) Returns the next ID for the transaction.voidsetAfterState(Map<Integer, Integer> afterState) voidsetLocal(boolean local) voidsetNeedFormattingCleanup(boolean needFormattingCleanup) static voidImplements the functionality of `y.transact(()=>{..})`.static voidImplements the functionality of `y.transact(()=>{..})`.static voidImplements the functionality of `y.transact(()=>{..})`.static voidtransact(Doc doc, Consumer<Transaction> f) Implements the functionality of `y.transact(()=>{..})`.static voidtransact(Doc doc, Consumer<Transaction> f, Object origin) Implements the functionality of `y.transact(()=>{..})`.static voidtransact(Doc doc, Consumer<Transaction> f, Object origin, boolean local) Implements the functionality of `y.transact(()=>{..})`.static <T> Ttransact(Doc doc, Function<Transaction, T> f) Implements the functionality of `y.transact(()=>{..})`.static <T> Ttransact(Doc doc, Function<Transaction, T> f, Object origin) Implements the functionality of `y.transact(()=>{..})`.static <T> Ttransact(Doc doc, Function<Transaction, T> f, Object origin, boolean local) Implements the functionality of `y.transact(()=>{..})`.static voidAttempts to garbage collect the delete set.static booleanwriteUpdateMessageFromTransaction(UpdateEncoder encoder, Transaction transaction) Writes an update message from the transaction to the encoder.
-
Constructor Details
-
Transaction
Constructor for the Transaction class.- Parameters:
doc- The Yjs document instance.origin- The origin of the transaction.local- Whether this change originates from this doc.
-
-
Method Details
-
getDoc
-
getBeforeState
-
getAfterState
-
setAfterState
-
getChanged
-
getChangedParentTypes
-
getDeleteSet
-
getOrigin
-
getMeta
-
getMergeStructs
-
isLocal
public boolean isLocal() -
setLocal
public void setLocal(boolean local) -
getSubdocsAdded
-
getSubdocsRemoved
-
getSubdocsLoaded
-
isNeedFormattingCleanup
public boolean isNeedFormattingCleanup() -
setNeedFormattingCleanup
public void setNeedFormattingCleanup(boolean needFormattingCleanup) -
writeUpdateMessageFromTransaction
public static boolean writeUpdateMessageFromTransaction(UpdateEncoder encoder, Transaction transaction) Writes an update message from the transaction to the encoder.- Parameters:
encoder- The encoder (either UpdateEncoderV1 or UpdateEncoderV2).transaction- The transaction object.- Returns:
- Whether data was written.
-
nextID
Returns the next ID for the transaction.- Parameters:
transaction- The transaction object.- Returns:
- The next ID.
-
addChangedTypeToTransaction
public static void addChangedTypeToTransaction(Transaction transaction, AbstractType type, String parentSub) Adds a changed type to the transaction.- Parameters:
transaction- The transaction object.type- The type of the object that changed.parentSub- The parent sub key.
-
tryGc
Attempts to garbage collect the delete set.- Parameters:
ds- The delete set.store- The struct store.gcFilter- The garbage collection filter function.
-
transact
Implements the functionality of `y.transact(()=>{..})`.- Parameters:
doc- The Yjs document.f- The Runnable function to execute within the transaction.
-
transact
Implements the functionality of `y.transact(()=>{..})`.- Parameters:
doc- The Yjs document.f- The function to execute within the transaction.
-
transact
Implements the functionality of `y.transact(()=>{..})`.- Parameters:
doc- The Yjs document.f- The function to execute within the transaction.- Returns:
- The result of the function.
-
transact
Implements the functionality of `y.transact(()=>{..})`.- Parameters:
doc- The Yjs document.f- The Runnable function to execute within the transaction.origin- The origin of the transaction.
-
transact
Implements the functionality of `y.transact(()=>{..})`.- Parameters:
doc- The Yjs document.f- The function to execute within the transaction.origin- The origin of the transaction.
-
transact
Implements the functionality of `y.transact(()=>{..})`.- Parameters:
doc- The Yjs document.f- The function to execute within the transaction.origin- The origin of the transaction.- Returns:
- The result of the function.
-
transact
Implements the functionality of `y.transact(()=>{..})`.- Parameters:
doc- The Yjs document.f- The Runnable to execute within the transaction.origin- The origin of the transaction.local- Whether the transaction is local.
-
transact
Implements the functionality of `y.transact(()=>{..})`.- Parameters:
doc- The Yjs document.f- The Consumer to execute within the transaction.origin- The origin of the transaction.local- Whether the transaction is local.
-
transact
Implements the functionality of `y.transact(()=>{..})`.- Parameters:
doc- The Yjs document.f- The Function to execute within the transaction.origin- The origin of the transaction.local- Whether the transaction is local.- Returns:
- The result of the function.
-