Class Doc


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

      • 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 Detail

      • isGc

        public boolean isGc()
      • setGc

        public void setGc​(boolean gc)
      • getGcFilter

        public java.util.function.Function<Item,​java.lang.Boolean> getGcFilter()
      • getClientID

        public int getClientID()
      • setClientID

        public void setClientID​(int clientID)
      • getGuid

        public java.lang.String getGuid()
      • setGuid

        public void setGuid​(java.lang.String guid)
      • getCollectionID

        public java.lang.String getCollectionID()
      • setCollectionID

        public void setCollectionID​(java.lang.String collectionID)
      • getShare

        public java.util.Map<java.lang.String,​AbstractType> getShare()
      • setTransaction

        public void setTransaction​(Transaction transaction)
      • getTransactionCleanups

        public java.util.List<Transaction> getTransactionCleanups()
      • setTransactionCleanups

        public void setTransactionCleanups​(java.util.List<Transaction> transactionCleanups)
      • getItem

        public Item getItem()
      • setItem

        public void setItem​(Item item)
      • isShouldLoad

        public boolean isShouldLoad()
      • isAutoLoad

        public boolean isAutoLoad()
      • getMeta

        public java.lang.Object getMeta()
      • isLoaded

        public boolean isLoaded()
      • isSynced

        public boolean isSynced()
      • getWhenLoaded

        public java.util.concurrent.CompletableFuture<Doc> getWhenLoaded()
      • getWhenSynced

        public java.util.concurrent.CompletableFuture<java.lang.Void> getWhenSynced()
      • onLoad

        public void onLoad​(java.util.function.Consumer<Doc> f)
      • onDestroy

        public void onDestroy​(java.util.function.Consumer<Doc> f)
      • onSync

        public void onSync​(java.util.function.BiConsumer<java.lang.Boolean,​Doc> f)
      • onUpdate

        public void onUpdate​(java.util.function.Consumer<Uint8Array> f)
      • onBeforeAllTransactions

        public void onBeforeAllTransactions​(java.util.function.Consumer<Doc> f)
      • onBeforeTransaction

        public void onBeforeTransaction​(java.util.function.BiConsumer<Transaction,​Doc> f)
      • onBeforeObserverCalls

        public void onBeforeObserverCalls​(java.util.function.BiConsumer<Transaction,​Doc> f)
      • onAfterTransaction

        public void onAfterTransaction​(java.util.function.BiConsumer<Transaction,​Doc> f)
      • onAfterTransactionCleanupCalls

        public void onAfterTransactionCleanupCalls​(java.util.function.BiConsumer<Transaction,​Doc> f)
      • onAfterAllTransactions

        public void onAfterAllTransactions​(java.util.function.BiConsumer<Doc,​java.util.List<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 java.util.Set<Doc> getSubdocs()
      • getSubdocGuids

        public java.util.Set<java.lang.String> getSubdocGuids()
      • transact

        public void transact​(java.lang.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​(java.util.function.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​(java.util.function.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​(java.lang.Runnable f,
                             java.lang.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​(java.util.function.Consumer<Transaction> f,
                             java.lang.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​(java.util.function.Function<Transaction,​T> f,
                              java.lang.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​(java.lang.String name,
                                              java.lang.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​(java.lang.String name)
      • getText

        public YText getText()
      • getText

        public YText getText​(java.lang.String name)
      • getMap

        public YMap getMap()
      • getMap

        public YMap getMap​(java.lang.String name)
      • getXmlElement

        public YXmlElement getXmlElement​(java.lang.String name)
      • getXmlFragment

        public YXmlFragment getXmlFragment​(java.lang.String name)
      • toJSON

        public java.util.Map<java.lang.String,​java.lang.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