Skip to content

BlockSuite API Documentation / @blocksuite/store / Y / Doc

Class: Doc ​

A Yjs instance handles the state of shared data.

Contents ​

Extends ​

  • Observable<string>

Constructors ​

new Doc(opts) ​

new Doc(opts?): Doc

Parameters ​

• opts?: DocOpts

configuration

Returns ​

Doc

Overrides ​

Observable<string>.constructor

Source ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/utils/Doc.d.ts:20

Properties ​

_item ​

_item: null | Item

If this document is a subdocument - a document integrated into another document - then _item is defined.

Source ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/utils/Doc.d.ts:47


_observers ​

_observers: Map<string, any>

Some desc.

Inherited from ​

Observable._observers

Source ​

node_modules/.pnpm/lib0@0.2.88/node_modules/lib0/observable.d.ts:58


_transaction ​

_transaction: null | Transaction

Source ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/utils/Doc.d.ts:34


_transactionCleanups ​

_transactionCleanups: Transaction[]

Source ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/utils/Doc.d.ts:38


autoLoad ​

autoLoad: boolean

Source ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/utils/Doc.d.ts:49


clientID ​

clientID: number

Source ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/utils/Doc.d.ts:23


collectionid ​

collectionid: null | string

Source ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/utils/Doc.d.ts:25


gc ​

gc: boolean

Source ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/utils/Doc.d.ts:21


gcFilter ​

gcFilter: (arg0) => boolean

Parameters ​

• arg0: Item

Returns ​

boolean

Source ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/utils/Doc.d.ts:22


guid ​

guid: string

Source ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/utils/Doc.d.ts:24


isLoaded ​

isLoaded: boolean

This is set to true when the persistence provider loaded the document from the database or when the sync event fires. Note that not all providers implement this feature. Provider authors are encouraged to fire the load event when the doc content is loaded from the database.

Source ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/utils/Doc.d.ts:57


isSynced ​

isSynced: boolean

This is set to true when the connection provider has successfully synced with a backend. Note that when using peer-to-peer providers this event may not provide very useful. Also note that not all providers implement this feature. Provider authors are encouraged to fire the sync event when the doc has been synced (with true as a parameter) or if connection is lost (with false as a parameter).

Source ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/utils/Doc.d.ts:65


meta ​

meta: any

Source ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/utils/Doc.d.ts:50


share ​

share: Map<string, AbstractType<YEvent<any>>>

Source ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/utils/Doc.d.ts:29


shouldLoad ​

shouldLoad: boolean

Source ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/utils/Doc.d.ts:48


store ​

store: StructStore

Source ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/utils/Doc.d.ts:30


subdocs ​

subdocs: Set<Doc>

Source ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/utils/Doc.d.ts:42


whenLoaded ​

whenLoaded: Promise<any>

Promise that resolves once the document has been loaded from a presistence provider.

Source ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/utils/Doc.d.ts:69


whenSynced ​

whenSynced: Promise<any>

Source ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/utils/Doc.d.ts:70

Methods ​

destroy() ​

destroy(): void

Returns ​

void

Inherited from ​

Observable.destroy

Source ​

node_modules/.pnpm/lib0@0.2.88/node_modules/lib0/observable.d.ts:84


emit() ​

emit(name, args): void

Emit a named event. All registered event listeners that listen to the specified name will receive the event.

Parameters ​

• name: string

The event name.

• args: any[]

The arguments that are applied to the event listener.

Returns ​

void

Inherited from ​

Observable.emit

Todo ​

This should catch exceptions

Source ​

node_modules/.pnpm/lib0@0.2.88/node_modules/lib0/observable.d.ts:83


get() ​

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: string

• TypeConstructor?: Function

The constructor of the type definition. E.g. Y.Text, Y.Array, Y.Map, ...

Returns ​

AbstractType<any>

The created type. Constructed with TypeConstructor

Example ​

ts
const y = new Y(..)
  const appState = {
    document: y.getText('document')
    comments: y.getArray('comments')
  }

Source ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/utils/Doc.d.ts:121


getArray() ​

getArray<T_1>(name?): Array<T_1>

Type parameters ​

• T_1

Parameters ​

• name?: string

Returns ​

Array<T_1>

Source ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/utils/Doc.d.ts:129


getMap() ​

getMap<T_2>(name?): Map<T_2>

Type parameters ​

• T_2

Parameters ​

• name?: string

Returns ​

Map<T_2>

Source ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/utils/Doc.d.ts:144


getSubdocGuids() ​

getSubdocGuids(): Set<string>

Returns ​

Set<string>

Source ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/utils/Doc.d.ts:80


getSubdocs() ​

getSubdocs(): Set<Doc>

Returns ​

Set<Doc>

Source ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/utils/Doc.d.ts:79


getText() ​

getText(name?): Text

Parameters ​

• name?: string

Returns ​

Text

Source ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/utils/Doc.d.ts:136


getXmlFragment() ​

getXmlFragment(name?): XmlFragment

Parameters ​

• name?: string

Returns ​

XmlFragment

Source ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/utils/Doc.d.ts:151


load() ​

load(): void

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.

Returns ​

void

Source ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/utils/Doc.d.ts:78


off() ​

off(name, f): void

Parameters ​

• name: string

• f: Function

Returns ​

void

Inherited from ​

Observable.off

Source ​

node_modules/.pnpm/lib0@0.2.88/node_modules/lib0/observable.d.ts:73


on() ​

on(eventName, f): void

Parameters ​

• eventName: string

• f: (...args) => any

Returns ​

void

Overrides ​

Observable.on

Source ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/utils/Doc.d.ts:167


once() ​

once(name, f): void

Parameters ​

• name: string

• f: Function

Returns ​

void

Inherited from ​

Observable.once

Source ​

node_modules/.pnpm/lib0@0.2.88/node_modules/lib0/observable.d.ts:68


toJSON() ​

toJSON(): Object

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 ​

Object

Deprecated ​

Do not use this method and rather call toJSON directly on the shared types.

Source ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/utils/Doc.d.ts:160


transact() ​

transact<T>(f, origin?): T

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.

Type parameters ​

• T

Parameters ​

• f: (arg0) => T

The function that should be executed as a transaction

• origin?: any

Origin of who started the transaction. Will be stored on transaction.origin

Returns ​

T

T

Source ​

node_modules/.pnpm/yjs@13.6.10/node_modules/yjs/dist/src/utils/Doc.d.ts:94


Generated using typedoc-plugin-markdown and TypeDoc