new Doc(conf)
Parameters:
| Name | Type | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
conf |
Object | configuration Properties
|
Extends
- Observable.<string>
Members
-
_transaction :Transaction|null
-
-
_transactionCleanups :Array.<Transaction>
-
-
share :Map.<string, AbstractType.<YEvent>>
-
Methods
-
destroy()
-
Emit
destroyevent and unregister all event handlers. -
get(name, TypeConstructor) → {AbstractType.<any>}
-
Define a shared data type.
Multiple calls of
y.get(name, TypeConstructor)yield the same result and do not overwrite each other. I.e.y.define(name, Y.Array) === y.define(name, Y.Array)After this method is called, the type is also available on
y.share.get(name).Best Practices: Define all types right after the Yjs instance is created and store them in a separate object. Also use the typed methods
getText(name),getArray(name), ..Parameters:
Name Type Description namestring TypeConstructorfunction The constructor of the type definition. E.g. Y.Text, Y.Array, Y.Map, ...
Example
const y = new Y(..) const appState = { document: y.getText('document') comments: y.getArray('comments') } -
getArray(nameopt) → {YArray.<T>}
-
Parameters:
Name Type Attributes Description namestring <optional>
Returns:
YArray.<T> -
getMap(nameopt) → {YMap.<any>}
-
Parameters:
Name Type Attributes Description namestring <optional>
Returns:
YMap.<any> -
getText(nameopt) → {YText}
-
Parameters:
Name Type Attributes Description namestring <optional>
Returns:
YText -
getXmlFragment(nameopt) → {YXmlFragment}
-
Parameters:
Name Type Attributes Description namestring <optional>
Returns:
YXmlFragment -
off(eventName, f)
-
Parameters:
Name Type Description eventNamestring ffunction -
on(eventName, f)
-
Parameters:
Name Type Description eventNamestring ffunction -
toJSON() → {Object.<string, any>}
-
Converts the entire document into a js object, recursively traversing each yjs type
Returns:
Object.<string, any> -
transact(f, originopt)
-
Changes that happen inside of a transaction are bundled. This means that the observer fires after the transaction is finished and that all changes that happened inside of the transaction are sent as one message to the other peers.
Parameters:
Name Type Attributes Default Description ffunction The function that should be executed as a transaction
originany <optional>
null Origin of who started the transaction. Will be stored on transaction.origin