new Y(conf)
Parameters:
| Name | Type | Description |
|---|---|---|
conf |
Object | undefined | configuration |
Extends
- Observable.<string>
Members
-
share :Map.<string, AbstractType.<YEvent>>
-
Methods
-
protected 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
Example
const y = new Y(..) const appState = { document: y.getText('document') comments: y.getArray('comments') } -
getArray(name) → {YArray.<T>}
-
Parameters:
Name Type Description namestring Returns:
YArray.<T> -
getMap(name) → {YMap.<any>}
-
Parameters:
Name Type Description namestring Returns:
YMap.<any> -
getText(name) → {YText}
-
Parameters:
Name Type Description namestring Returns:
YText -
getXmlFragment(name) → {YXmlFragment}
-
Parameters:
Name Type Description namestring Returns:
YXmlFragment -
off(eventName, f)
-
Parameters:
Name Type Description eventNamestring ffunction -
on(eventName, f)
-
Parameters:
Name Type Description eventNamestring ffunction -
transact(f)
-
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 Description ffunction The function that should be executed as a transaction