Class Transaction

java.lang.Object
io.keikai.doc.collab.utils.Transaction

public class Transaction extends Object
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 Details

    • Transaction

      public Transaction(Doc doc, Object origin, boolean local)
      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

      public Doc getDoc()
    • getBeforeState

      public Map<Integer,Integer> getBeforeState()
    • getAfterState

      public Map<Integer,Integer> getAfterState()
    • setAfterState

      public void setAfterState(Map<Integer,Integer> afterState)
    • getChanged

      public Map<AbstractType,Set<String>> getChanged()
    • getChangedParentTypes

      public Map<AbstractType,List<YEvent>> getChangedParentTypes()
    • getDeleteSet

      public DeleteSet getDeleteSet()
    • getOrigin

      public Object getOrigin()
    • getMeta

      public Map<Object,Object> getMeta()
    • getMergeStructs

      public List<AbstractStruct> getMergeStructs()
    • isLocal

      public boolean isLocal()
    • setLocal

      public void setLocal(boolean local)
    • getSubdocsAdded

      public Set<Doc> getSubdocsAdded()
    • getSubdocsRemoved

      public Set<Doc> getSubdocsRemoved()
    • getSubdocsLoaded

      public Set<Doc> 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

      public static ID nextID(Transaction transaction)
      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

      public static void tryGc(DeleteSet ds, StructStore store, Function<Item,Boolean> gcFilter)
      Attempts to garbage collect the delete set.
      Parameters:
      ds - The delete set.
      store - The struct store.
      gcFilter - The garbage collection filter function.
    • transact

      public static void transact(Doc doc, Runnable f)
      Implements the functionality of `y.transact(()=>{..})`.
      Parameters:
      doc - The Yjs document.
      f - The Runnable function to execute within the transaction.
    • transact

      public static void transact(Doc doc, Consumer<Transaction> f)
      Implements the functionality of `y.transact(()=>{..})`.
      Parameters:
      doc - The Yjs document.
      f - The function to execute within the transaction.
    • transact

      public static <T> T transact(Doc doc, Function<Transaction,T> f)
      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

      public static void transact(Doc doc, Runnable f, Object origin)
      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

      public static void transact(Doc doc, Consumer<Transaction> f, Object origin)
      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

      public static <T> T transact(Doc doc, Function<Transaction,T> f, Object origin)
      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

      public static void transact(Doc doc, Runnable f, Object origin, boolean local)
      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

      public static void transact(Doc doc, Consumer<Transaction> f, Object origin, boolean local)
      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

      public static <T> T transact(Doc doc, Function<Transaction,T> f, Object origin, boolean local)
      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.