[]
        
(Showing Draft Content)

SharedDoc

Class: SharedDoc<S, T>

Represents a shared document for requesting snapshots and operations.

Type parameters

Name Type Description
S unknown The type of snapshot data.
T unknown The type of operation data.

Table of contents

Constructors

Accessors

Methods

Constructors

constructor

• new SharedDoc<S, T>(conn)

Creates a new shared document instance.

Type parameters

Name Type
S unknown
T unknown

Parameters

Name Type
conn Connection

Accessors

connection

• get connection(): Connection

Retrieves the connection associated with the shared document.

Returns

Connection

The connection instance.


data

• get data(): undefined | S

Retrieves the data of the current snapshot.

Returns

undefined | S


id

• get id(): string

Retrieves the ID of the shared document.

Returns

string

The document ID.


type

• get type(): undefined | OT_Type<S, T>

Retrieves the OT type of the snapshot.

Returns

undefined | OT_Type<S, T>


version

• get version(): undefined | number

Retrieves the version of the current snapshot.

Returns

undefined | number

Methods

create

▸ create(data, type, options): Promise<void>

Create a new document.

Parameters

Name Type Description
data S The data used to initialize the snapshot.
type string The URI of the OT type.
options IOptions Options for the operation.

Returns

Promise<void>

A promise that resolves after the document is created.


del

▸ del(options): Promise<void>

Delete the document.

Parameters

Name Type Description
options IOptions The options of the op.

Returns

Promise<void>

A promise that resolves after the document is deleted.


destroy

▸ destroy(): void

Destroys the observable and cleans up resources.

Returns

void


fetch

▸ fetch(): Promise<void>

Fetches the snapshot data.

Returns

Promise<void>

A promise that resolves after the snapshot is fetched, the fetched snapshot data is 'doc.data'.


fetchHistorySnapshot

▸ fetchHistorySnapshot(options): Promise<ISnapshot<S>>

Fetches the history snapshot data.

Parameters

Name Type Description
options IHistorySnapshotRequestOptions Options for the history snapshot request.

Returns

Promise<ISnapshot<S>>

A promise that resolves after the history snapshot is fetched.


hardRollback

▸ hardRollback(): Promise<void>

Hard rolls back the snapshot data to the latest version.

Returns

Promise<void>

A promise that resolves when the rollback is complete.


off

▸ off<NAME>(name, f): void

Removes a listener for a specific event.

Type parameters

Name Type Description
NAME extends keyof ISharedDocEvents<S, T> The type of the event name, extending keyof ISharedDocEvents<S, T>.

Parameters

Name Type Description
name NAME The name of the event.
f ISharedDocEvents<S, T>[NAME] The event handler function to remove.

Returns

void


on

▸ on<NAME>(name, f): ISharedDocEvents<S, T>[NAME]

Registers a listener for a specific event.

Type parameters

Name Type Description
NAME extends keyof ISharedDocEvents<S, T> The type of the event name, extending keyof ISharedDocEvents<S, T>.

Parameters

Name Type Description
name NAME The name of the event.
f ISharedDocEvents<S, T>[NAME] The event handler function.

Returns

ISharedDocEvents<S, T>[NAME]

The registered event handler.


once

▸ once<NAME>(name, f): void

Registers a one-time listener for a specific event.

Type parameters

Name Type Description
NAME extends keyof ISharedDocEvents<S, T> The type of the event name, extending keyof ISharedDocEvents<S, T>.

Parameters

Name Type Description
name NAME The name of the event.
f ISharedDocEvents<S, T>[NAME] The event handler function to call once.

Returns

void


restore

▸ restore(targetVersion, options?): Promise<void>

Restore the document to a specific version.

Parameters

Name Type Description
targetVersion number The target version number to restore to.
options? IOptions The options of the op.

Returns

Promise<void>

A promise that resolves after the document is restored.


submitOp

▸ submitOp(component, options?): Promise<void>

Submits an op to the document.

Parameters

Name Type Description
component T The op component.
options? IOptions -

Returns

Promise<void>

A promise that resolves after the op is submitted.


subscribe

▸ subscribe(): Promise<void>

Subscribes the snapshot data.

Returns

Promise<void>

A promise that resolves after the snapshot is subscribed, the subscribed snapshot data is 'doc.data'.