Package io.keikai.doc.collab.utils
Class Doc
- java.lang.Object
-
- io.keikai.doc.collab.lib0.ObservableV2
-
- io.keikai.doc.collab.utils.Doc
-
public class Doc extends ObservableV2
A Yjs instance handles the state of shared data.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voiddestroy()Emit `destroy` event and unregister all event handlers.<T extends AbstractType>
Tget(java.lang.String name, java.lang.Class<? extends AbstractType> typeClz)Define a shared data type.YArraygetArray()YArraygetArray(java.lang.String name)intgetClientID()java.lang.StringgetCollectionID()java.util.function.Function<Item,java.lang.Boolean>getGcFilter()java.lang.StringgetGuid()ItemgetItem()YMapgetMap()YMapgetMap(java.lang.String name)java.lang.ObjectgetMeta()java.util.Map<java.lang.String,AbstractType>getShare()StructStoregetStore()java.util.Set<java.lang.String>getSubdocGuids()java.util.Set<Doc>getSubdocs()YTextgetText()YTextgetText(java.lang.String name)TransactiongetTransaction()java.util.List<Transaction>getTransactionCleanups()java.util.concurrent.CompletableFuture<Doc>getWhenLoaded()java.util.concurrent.CompletableFuture<java.lang.Void>getWhenSynced()YXmlElementgetXmlElement()YXmlElementgetXmlElement(java.lang.String name)YXmlFragmentgetXmlFragment()YXmlFragmentgetXmlFragment(java.lang.String name)booleanisAutoLoad()booleanisGc()booleanisLoaded()booleanisShouldLoad()booleanisSynced()voidload()Notify the parent document that you request to load data into this subdocument (if it is a subdocument).voidonAfterAllTransactions(java.util.function.BiConsumer<Doc,java.util.List<Transaction>> f)voidonAfterTransaction(java.util.function.BiConsumer<Transaction,Doc> f)voidonAfterTransactionCleanupCalls(java.util.function.BiConsumer<Transaction,Doc> f)voidonBeforeAllTransactions(java.util.function.Consumer<Doc> f)voidonBeforeObserverCalls(java.util.function.BiConsumer<Transaction,Doc> f)voidonBeforeTransaction(java.util.function.BiConsumer<Transaction,Doc> f)voidonDestroy(java.util.function.Consumer<Doc> f)voidonLoad(java.util.function.Consumer<Doc> f)voidonSubdocs(TriConsumer<DocSubdoc,Doc,Transaction> f)voidonSync(java.util.function.BiConsumer<java.lang.Boolean,Doc> f)voidonUpdate(QuadConsumer<Uint8Array,java.lang.Object,Doc,Transaction> f)voidonUpdate(java.util.function.Consumer<Uint8Array> f)voidonUpdateV2(QuadConsumer<Uint8Array,java.lang.Object,Doc,Transaction> f)voidsetClientID(int clientID)voidsetCollectionID(java.lang.String collectionID)voidsetGc(boolean gc)voidsetGuid(java.lang.String guid)voidsetItem(Item item)voidsetTransaction(Transaction transaction)voidsetTransactionCleanups(java.util.List<Transaction> transactionCleanups)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.voidtransact(java.lang.Runnable f)Changes that happen inside a transaction are bundled.voidtransact(java.lang.Runnable f, java.lang.Object origin)Changes that happen inside a transaction are bundled.voidtransact(java.util.function.Consumer<Transaction> f)Changes that happen inside a transaction are bundled.voidtransact(java.util.function.Consumer<Transaction> f, java.lang.Object origin)Changes that happen inside a transaction are bundled.<T> Ttransact(java.util.function.Function<Transaction,T> f)Changes that happen inside a transaction are bundled.<T> Ttransact(java.util.function.Function<Transaction,T> f, java.lang.Object origin)Changes that happen inside a transaction are bundled.
-
-
-
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()
-
getStore
public StructStore getStore()
-
getTransaction
public Transaction getTransaction()
-
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)
-
onUpdate
public void onUpdate(QuadConsumer<Uint8Array,java.lang.Object,Doc,Transaction> f)
-
onUpdateV2
public void onUpdateV2(QuadConsumer<Uint8Array,java.lang.Object,Doc,Transaction> 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)
-
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 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 transactionorigin- 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 transactionorigin- 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 transactionorigin- 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()
-
getXmlElement
public YXmlElement getXmlElement(java.lang.String name)
-
getXmlFragment
public YXmlFragment getXmlFragment()
-
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:
destroyin classObservableV2
-
-