Skip to content

BlockSuite API Documentation / @blocksuite/store / BlockSuiteDoc

Class: BlockSuiteDoc

A Yjs instance handles the state of shared data.

Extends

Constructors

new BlockSuiteDoc(opts)

new BlockSuiteDoc(opts?): BlockSuiteDoc

Parameters

opts?: DocOpts

configuration

Returns

BlockSuiteDoc

Inherited from

Doc.constructor

Source

node_modules/.pnpm/yjs@13.6.14/node_modules/yjs/dist/src/utils/Doc.d.ts:35

Properties

_item

_item: null | Item

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

Inherited from

Doc._item

Source

node_modules/.pnpm/yjs@13.6.14/node_modules/yjs/dist/src/utils/Doc.d.ts:62


_observers

_observers: Map<string, Set<any>>

Some desc.

Inherited from

Doc._observers

Source

node_modules/.pnpm/lib0@0.2.93/node_modules/lib0/observable.d.ts:15


_spaces

private _spaces: Map<Doc>

Source

packages/framework/store/src/yjs/doc.ts:13


_transaction

_transaction: null | Transaction

Inherited from

Doc._transaction

Source

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


_transactionCleanups

_transactionCleanups: Transaction[]

Inherited from

Doc._transactionCleanups

Source

node_modules/.pnpm/yjs@13.6.14/node_modules/yjs/dist/src/utils/Doc.d.ts:53


autoLoad

autoLoad: boolean

Inherited from

Doc.autoLoad

Source

node_modules/.pnpm/yjs@13.6.14/node_modules/yjs/dist/src/utils/Doc.d.ts:64


clientID

clientID: number

Inherited from

Doc.clientID

Source

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


collectionid

collectionid: null | string

Inherited from

Doc.collectionid

Source

node_modules/.pnpm/yjs@13.6.14/node_modules/yjs/dist/src/utils/Doc.d.ts:40


gc

gc: boolean

Inherited from

Doc.gc

Source

node_modules/.pnpm/yjs@13.6.14/node_modules/yjs/dist/src/utils/Doc.d.ts:36


gcFilter()

gcFilter: (arg0) => boolean

Parameters

arg0: Item

Returns

boolean

Inherited from

Doc.gcFilter

Source

node_modules/.pnpm/yjs@13.6.14/node_modules/yjs/dist/src/utils/Doc.d.ts:37


guid

guid: string

Inherited from

Doc.guid

Source

node_modules/.pnpm/yjs@13.6.14/node_modules/yjs/dist/src/utils/Doc.d.ts:39


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.

Inherited from

Doc.isLoaded

Source

node_modules/.pnpm/yjs@13.6.14/node_modules/yjs/dist/src/utils/Doc.d.ts:72


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).

Inherited from

Doc.isSynced

Source

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


meta

meta: any

Inherited from

Doc.meta

Source

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


share

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

Inherited from

Doc.share

Source

node_modules/.pnpm/yjs@13.6.14/node_modules/yjs/dist/src/utils/Doc.d.ts:44


shouldLoad

shouldLoad: boolean

Inherited from

Doc.shouldLoad

Source

node_modules/.pnpm/yjs@13.6.14/node_modules/yjs/dist/src/utils/Doc.d.ts:63


store

store: StructStore

Inherited from

Doc.store

Source

node_modules/.pnpm/yjs@13.6.14/node_modules/yjs/dist/src/utils/Doc.d.ts:45


subdocs

subdocs: Set<Doc>

Inherited from

Doc.subdocs

Source

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


whenLoaded

whenLoaded: Promise<any>

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

Inherited from

Doc.whenLoaded

Source

node_modules/.pnpm/yjs@13.6.14/node_modules/yjs/dist/src/utils/Doc.d.ts:84


whenSynced

whenSynced: Promise<any>

Inherited from

Doc.whenSynced

Source

node_modules/.pnpm/yjs@13.6.14/node_modules/yjs/dist/src/utils/Doc.d.ts:85

Accessors

spaces

get spaces(): Map<Doc>

Returns

Map<Doc>

Source

packages/framework/store/src/yjs/doc.ts:15

Methods

destroy()

destroy(): void

Returns

void

Inherited from

Doc.destroy

Source

node_modules/.pnpm/lib0@0.2.93/node_modules/lib0/observable.d.ts:45


emit()

emit<NAME_3>(name, args): void

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

Type parameters

NAME_3 extends "subdocs" | "destroy" | "load" | "sync" | "update" | "updateV2" | "beforeAllTransactions" | "beforeTransaction" | "beforeObserverCalls" | "afterTransaction" | "afterTransactionCleanup" | "afterAllTransactions"

Parameters

name: NAME_3

The event name.

args: Parameters<DocEvents[NAME_3]>

The arguments that are applied to the event listener.

Returns

void

Inherited from

Doc.emit

Todo

This should catch exceptions

Source

node_modules/.pnpm/lib0@0.2.93/node_modules/lib0/observable.d.ts:44


get()

get<Type>(name, TypeConstructor?): InstanceType<Type>

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), ..

Type parameters

Type extends () => AbstractType<any>

Parameters

name: string

TypeConstructor?: Type

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

Returns

InstanceType<Type>

The created type. Constructed with TypeConstructor

Inherited from

Doc.get

Example

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

Source

node_modules/.pnpm/yjs@13.6.14/node_modules/yjs/dist/src/utils/Doc.d.ts:137


getArray()

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

Type parameters

T_1

Parameters

name?: string

Returns

Array<T_1>

Inherited from

Doc.getArray

Source

node_modules/.pnpm/yjs@13.6.14/node_modules/yjs/dist/src/utils/Doc.d.ts:147


getArrayProxy()

getArrayProxy<Key, Value>(key): Value

Type parameters

Key extends string

Value extends unknown[] = never

Parameters

key: Key

Returns

Value

Source

packages/framework/store/src/yjs/doc.ts:46


getMap()

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

Type parameters

T_2

Parameters

name?: string

Returns

Map<T_2>

Inherited from

Doc.getMap

Source

node_modules/.pnpm/yjs@13.6.14/node_modules/yjs/dist/src/utils/Doc.d.ts:162


getMapProxy()

getMapProxy<Key, Value>(key): Value

Type parameters

Key extends string

Value extends Record<string, unknown> = never

Parameters

key: Key

Returns

Value

Source

packages/framework/store/src/yjs/doc.ts:33


getSubdocGuids()

getSubdocGuids(): Set<string>

Returns

Set<string>

Inherited from

Doc.getSubdocGuids

Source

node_modules/.pnpm/yjs@13.6.14/node_modules/yjs/dist/src/utils/Doc.d.ts:95


getSubdocs()

getSubdocs(): Set<Doc>

Returns

Set<Doc>

Inherited from

Doc.getSubdocs

Source

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


getText()

getText(name?): Text

Parameters

name?: string

Returns

Text

Inherited from

Doc.getText

Source

node_modules/.pnpm/yjs@13.6.14/node_modules/yjs/dist/src/utils/Doc.d.ts:154


getXmlElement()

getXmlElement(name?): XmlElement<object>

Parameters

name?: string

Returns

XmlElement<object>

Inherited from

Doc.getXmlElement

Source

node_modules/.pnpm/yjs@13.6.14/node_modules/yjs/dist/src/utils/Doc.d.ts:169


getXmlFragment()

getXmlFragment(name?): XmlFragment

Parameters

name?: string

Returns

XmlFragment

Inherited from

Doc.getXmlFragment

Source

node_modules/.pnpm/yjs@13.6.14/node_modules/yjs/dist/src/utils/Doc.d.ts:176


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

Inherited from

Doc.load

Source

node_modules/.pnpm/yjs@13.6.14/node_modules/yjs/dist/src/utils/Doc.d.ts:93


off()

off<NAME_2>(name, f): void

Type parameters

NAME_2 extends "subdocs" | "destroy" | "load" | "sync" | "update" | "updateV2" | "beforeAllTransactions" | "beforeTransaction" | "beforeObserverCalls" | "afterTransaction" | "afterTransactionCleanup" | "afterAllTransactions"

Parameters

name: NAME_2

f: DocEvents[NAME_2]

Returns

void

Inherited from

Doc.off

Source

node_modules/.pnpm/lib0@0.2.93/node_modules/lib0/observable.d.ts:33


on()

on<NAME>(name, f): DocEvents[NAME]

Type parameters

NAME extends "subdocs" | "destroy" | "load" | "sync" | "update" | "updateV2" | "beforeAllTransactions" | "beforeTransaction" | "beforeObserverCalls" | "afterTransaction" | "afterTransactionCleanup" | "afterAllTransactions"

Parameters

name: NAME

f: DocEvents[NAME]

Returns

DocEvents[NAME]

Inherited from

Doc.on

Source

node_modules/.pnpm/lib0@0.2.93/node_modules/lib0/observable.d.ts:21


once()

once<NAME_1>(name, f): void

Type parameters

NAME_1 extends "subdocs" | "destroy" | "load" | "sync" | "update" | "updateV2" | "beforeAllTransactions" | "beforeTransaction" | "beforeObserverCalls" | "afterTransaction" | "afterTransactionCleanup" | "afterAllTransactions"

Parameters

name: NAME_1

f: DocEvents[NAME_1]

Returns

void

Inherited from

Doc.once

Source

node_modules/.pnpm/lib0@0.2.93/node_modules/lib0/observable.d.ts:27


toJSON()

toJSON(): Record<string, any>

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

Record<string, any>

Overrides

Doc.toJSON

Deprecated

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

Source

packages/framework/store/src/yjs/doc.ts:20


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

The function that should be executed as a transaction

origin?: string | number

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

Returns

T

T

Overrides

Doc.transact

Source

packages/framework/store/src/yjs/doc.ts:56