Skip to content

API > @blocksuite/store > BlockSuiteDoc

Class: BlockSuiteDoc ​

A Yjs instance handles the state of shared data.

Extends ​

Constructors ​

constructor ​

new BlockSuiteDoc(opts?): BlockSuiteDoc

Parameters ​

ParameterTypeDescription
opts?DocOptsconfiguration

Returns ​

BlockSuiteDoc

Inherited from ​

Doc.constructor

Defined In ​

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.

Defined In ​

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

Inherited from ​

Doc._item


_observers ​

_observers: Map< string, any >

Some desc.

Defined In ​

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

Inherited from ​

Doc._observers


_spaces ​

private _spaces: Map< Doc >

Defined In ​

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


_transaction ​

_transaction: null | Transaction

Defined In ​

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

Inherited from ​

Doc._transaction


_transactionCleanups ​

_transactionCleanups: Transaction[]

Defined In ​

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

Inherited from ​

Doc._transactionCleanups


autoLoad ​

autoLoad: boolean

Defined In ​

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

Inherited from ​

Doc.autoLoad


clientID ​

clientID: number

Defined In ​

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

Inherited from ​

Doc.clientID


collectionid ​

collectionid: null | string

Defined In ​

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

Inherited from ​

Doc.collectionid


gc ​

gc: boolean

Defined In ​

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

Inherited from ​

Doc.gc


gcFilter ​

gcFilter: function

Parameters ​

ParameterType
arg0Item

Returns ​

boolean

Defined In ​

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

Inherited from ​

Doc.gcFilter


guid ​

guid: string

Defined In ​

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

Inherited from ​

Doc.guid


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.

Defined In ​

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

Inherited from ​

Doc.isLoaded


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

Defined In ​

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

Inherited from ​

Doc.isSynced


meta ​

meta: any

Defined In ​

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

Inherited from ​

Doc.meta


share ​

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

Defined In ​

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

Inherited from ​

Doc.share


shouldLoad ​

shouldLoad: boolean

Defined In ​

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

Inherited from ​

Doc.shouldLoad


store ​

store: StructStore

Defined In ​

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

Inherited from ​

Doc.store


subdocs ​

subdocs: Set< Doc >

Defined In ​

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

Inherited from ​

Doc.subdocs


whenLoaded ​

whenLoaded: Promise< any >

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

Defined In ​

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

Inherited from ​

Doc.whenLoaded


whenSynced ​

whenSynced: Promise< any >

Defined In ​

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

Inherited from ​

Doc.whenSynced

Accessors ​

spaces ​

get spaces(): Map< Doc >

Defined In ​

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

Methods ​

destroy ​

destroy(): void

Returns ​

void

Inherited from ​

Doc.destroy

Defined In ​

node_modules/.pnpm/lib0@0.2.87/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 ​

ParameterTypeDescription
namestringThe event name.
argsany[]The arguments that are applied to the event listener.

Returns ​

void

Inherited from ​

Doc.emit

Todo ​

This should catch exceptions

Defined In ​

node_modules/.pnpm/lib0@0.2.87/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 ​

ParameterTypeDescription
namestring-
TypeConstructor?FunctionThe constructor of the type definition. E.g. Y.Text, Y.Array, Y.Map, ...

Returns ​

AbstractType< any >

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')
  }
const y = new Y(..)
  const appState = {
    document: y.getText('document')
    comments: y.getArray('comments')
  }

Defined In ​

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 ​

Parameter
T_1

Parameters ​

ParameterType
name?string

Returns ​

Array< T_1 >

Inherited from ​

Doc.getArray

Defined In ​

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


getArrayProxy ​

getArrayProxy<Key, Value>(key): Value

Type parameters ​

ParameterDefault
Key extends string-
Value extends unknown[]never

Parameters ​

ParameterType
keyKey

Returns ​

Value

Defined In ​

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


getMap ​

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

Type parameters ​

Parameter
T_2

Parameters ​

ParameterType
name?string

Returns ​

Map< T_2 >

Inherited from ​

Doc.getMap

Defined In ​

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


getMapProxy ​

getMapProxy<Key, Value>(key): Value

Type parameters ​

ParameterDefault
Key extends string-
Value extends Record< string, unknown >never

Parameters ​

ParameterType
keyKey

Returns ​

Value

Defined In ​

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


getSubdocGuids ​

getSubdocGuids(): Set< string >

Returns ​

Set< string >

Inherited from ​

Doc.getSubdocGuids

Defined In ​

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


getSubdocs ​

getSubdocs(): Set< Doc >

Returns ​

Set< Doc >

Inherited from ​

Doc.getSubdocs

Defined In ​

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


getText ​

getText(name?): Text

Parameters ​

ParameterType
name?string

Returns ​

Text

Inherited from ​

Doc.getText

Defined In ​

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


getXmlFragment ​

getXmlFragment(name?): XmlFragment

Parameters ​

ParameterType
name?string

Returns ​

XmlFragment

Inherited from ​

Doc.getXmlFragment

Defined In ​

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

Inherited from ​

Doc.load

Defined In ​

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


off ​

off(name, f): void

Parameters ​

ParameterType
namestring
fFunction

Returns ​

void

Inherited from ​

Doc.off

Defined In ​

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


on ​

on(eventName, f): void

Parameters ​

ParameterType
eventNamestring
ffunction

Returns ​

void

Inherited from ​

Doc.on

Defined In ​

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


once ​

once(name, f): void

Parameters ​

ParameterType
namestring
fFunction

Returns ​

void

Inherited from ​

Doc.once

Defined In ​

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


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.

Defined In ​

packages/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 ​

Parameter
T

Parameters ​

ParameterTypeDescription
ffunctionThe function that should be executed as a transaction
origin?string | numberOrigin of who started the transaction. Will be stored on transaction.origin

Returns ​

T

T

Overrides ​

Doc.transact

Defined In ​

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