Class Doc


public class Doc extends ObservableV2
A Yjs instance handles the state of shared data.
  • Constructor Details

    • Doc

      public Doc()
      A Yjs instance handles the state of shared data.
    • Doc

      public Doc(DocOpts opts)
      A Yjs instance handles the state of shared data.
      Parameters:
      opts - configuration
  • Method Details

    • isGc

      public boolean isGc()
    • setGc

      public void setGc(boolean gc)
    • getGcFilter

      public Function<Item,Boolean> getGcFilter()
    • getClientID

      public int getClientID()
    • setClientID

      public void setClientID(int clientID)
    • getGuid

      public String getGuid()
    • setGuid

      public void setGuid(String guid)
    • getCollectionID

      public String getCollectionID()
    • setCollectionID

      public void setCollectionID(String collectionID)
    • getShare

      public Map<String,AbstractType> getShare()
    • getStore

      public StructStore getStore()
    • getTransaction

      public Transaction getTransaction()
    • setTransaction

      public void setTransaction(Transaction transaction)
    • getTransactionCleanups

      public List<Transaction> getTransactionCleanups()
    • setTransactionCleanups

      public void setTransactionCleanups(List<Transaction> transactionCleanups)
    • getItem

      public Item getItem()
    • setItem

      public void setItem(Item item)
    • isShouldLoad

      public boolean isShouldLoad()
    • isAutoLoad

      public boolean isAutoLoad()
    • getMeta

      public Object getMeta()
    • isLoaded

      public boolean isLoaded()
    • isSynced

      public boolean isSynced()
    • getWhenLoaded

      public CompletableFuture<Doc> getWhenLoaded()
    • getWhenSynced

      public CompletableFuture<Void> getWhenSynced()
    • onLoad

      public void onLoad(Consumer<Doc> f)
    • onDestroy

      public void onDestroy(Consumer<Doc> f)
    • onSync

      public void onSync(BiConsumer<Boolean,Doc> f)
    • onUpdate

      public void onUpdate(Consumer<Uint8Array> f)
    • onUpdate

      public void onUpdate(QuadConsumer<Uint8Array,Object,Doc,Transaction> f)
    • onUpdateV2

      public void onUpdateV2(QuadConsumer<Uint8Array,Object,Doc,Transaction> f)
    • onBeforeAllTransactions

      public void onBeforeAllTransactions(Consumer<Doc> f)
    • onBeforeTransaction

      public void onBeforeTransaction(BiConsumer<Transaction,Doc> f)
    • onBeforeObserverCalls

      public void onBeforeObserverCalls(BiConsumer<Transaction,Doc> f)
    • onAfterTransaction

      public void onAfterTransaction(BiConsumer<Transaction,Doc> f)
    • onAfterTransactionCleanupCalls

      public void onAfterTransactionCleanupCalls(BiConsumer<Transaction,Doc> f)
    • onAfterAllTransactions

      public void onAfterAllTransactions(BiConsumer<Doc,List<Transaction>> f)
    • onSubdocs

      public void onSubdocs(TriConsumer<DocSubdoc,Doc,Transaction> f)
    • load

      public void load()
      Notify the parent document that you request to load data into this subdocument (if it is a subdocument).

      `load()` might be used in the future to request any provider to load the most current data.

      It is safe to call `load()` multiple times.

    • getSubdocs

      public Set<Doc> getSubdocs()
    • getSubdocGuids

      public Set<String> getSubdocGuids()
    • transact

      public void transact(Runnable f)
      Changes that happen inside a transaction are bundled. This means that the observer fires _after_ the transaction is finished and that all changes that happened inside the transaction are sent as one message to the other peers.
      Parameters:
      f - The Runnable function that should be executed as a transaction
    • transact

      public void transact(Consumer<Transaction> f)
      Changes that happen inside a transaction are bundled. This means that the observer fires _after_ the transaction is finished and that all changes that happened inside the transaction are sent as one message to the other peers.
      Parameters:
      f - The Consumer function that should be executed as a transaction
    • transact

      public <T> T transact(Function<Transaction,T> f)
      Changes that happen inside a transaction are bundled. This means that the observer fires _after_ the transaction is finished and that all changes that happened inside the transaction are sent as one message to the other peers.
      Parameters:
      f - The function that should be executed as a transaction
      Returns:
      T
    • transact

      public void transact(Runnable f, Object origin)
      Changes that happen inside a transaction are bundled. This means that the observer fires _after_ the transaction is finished and that all changes that happened inside the transaction are sent as one message to the other peers.
      Parameters:
      f - The Runnable function that should be executed as a transaction
      origin - Origin of who started the transaction. Will be stored on transaction.origin
    • transact

      public void transact(Consumer<Transaction> f, Object origin)
      Changes that happen inside a transaction are bundled. This means that the observer fires _after_ the transaction is finished and that all changes that happened inside the transaction are sent as one message to the other peers.
      Parameters:
      f - The Consumer function that should be executed as a transaction
      origin - Origin of who started the transaction. Will be stored on transaction.origin
    • transact

      public <T> T transact(Function<Transaction,T> f, Object origin)
      Changes that happen inside a transaction are bundled. This means that the observer fires _after_ the transaction is finished and that all changes that happened inside the transaction are sent as one message to the other peers.
      Parameters:
      f - The function that should be executed as a transaction
      origin - Origin of who started the transaction. Will be stored on transaction.origin
      Returns:
      T
    • get

      public <T extends AbstractType> T get(String name, Class<? extends AbstractType> typeClz)
      Define a shared data type.

      Multiple calls of `ydoc.get(name, typeClz)` yield the same result and do not overwrite each other. I.e. `ydoc.get(name, Y.Array) === ydoc.get(name, Y.Array)`

      After this method is called, the type is also available on `ydoc.share.get(name)`.

      *Best Practices:* Define all types right after the Y.Doc instance is created and store them in a separate object. Also use the typed methods `getText(name)`, `getArray(name)`, ..

      Parameters:
      name -
      typeClz - The class of the type definition. E.g. YText, YArray, YMap, ...
      Returns:
      The created type which class is typeClz
    • getArray

      public YArray getArray()
    • getArray

      public YArray getArray(String name)
    • getText

      public YText getText()
    • getText

      public YText getText(String name)
    • getMap

      public YMap getMap()
    • getMap

      public YMap getMap(String name)
    • getXmlElement

      public YXmlElement getXmlElement()
    • getXmlElement

      public YXmlElement getXmlElement(String name)
    • getXmlFragment

      public YXmlFragment getXmlFragment()
    • getXmlFragment

      public YXmlFragment getXmlFragment(String name)
    • toJSON

      public Map<String,Object> toJSON()
      Deprecated.
      Do not use this method and rather call toJSON directly on the shared types.
      Converts the entire document into a js object, recursively traversing each yjs type Doesn't log types that have not been defined (using ydoc.getType(..)).
      Returns:
      Map
    • destroy

      public void destroy()
      Emit `destroy` event and unregister all event handlers.
      Overrides:
      destroy in class ObservableV2