[]
Represents a shared document for requesting snapshots and operations.
| Name | Type | Description |
|---|---|---|
S |
unknown |
The type of snapshot data. |
T |
unknown |
The type of operation data. |
• new SharedDoc<S, T>(conn)
Creates a new shared document instance.
| Name | Type |
|---|---|
S |
unknown |
T |
unknown |
| Name | Type |
|---|---|
conn |
Connection |
• get connection(): Connection
Retrieves the connection associated with the shared document.
Connection
The connection instance.
• get data(): undefined | S
Retrieves the data of the current snapshot.
undefined | S
• get id(): string
Retrieves the ID of the shared document.
string
The document ID.
• get type(): undefined | OT_Type<S, T>
Retrieves the OT type of the snapshot.
undefined | OT_Type<S, T>
• get version(): undefined | number
Retrieves the version of the current snapshot.
undefined | number
▸ create(data, type, options): Promise<void>
Create a new document.
| 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. |
Promise<void>
A promise that resolves after the document is created.
▸ del(options): Promise<void>
Delete the document.
| Name | Type | Description |
|---|---|---|
options |
IOptions |
The options of the op. |
Promise<void>
A promise that resolves after the document is deleted.
▸ destroy(): void
Destroys the observable and cleans up resources.
void
▸ fetch(): Promise<void>
Fetches the snapshot data.
Promise<void>
A promise that resolves after the snapshot is fetched, the fetched snapshot data is 'doc.data'.
▸ fetchHistorySnapshot(options): Promise<ISnapshot<S>>
Fetches the history snapshot data.
| Name | Type | Description |
|---|---|---|
options |
IHistorySnapshotRequestOptions |
Options for the history snapshot request. |
Promise<ISnapshot<S>>
A promise that resolves after the history snapshot is fetched.
▸ hardRollback(): Promise<void>
Hard rolls back the snapshot data to the latest version.
Promise<void>
A promise that resolves when the rollback is complete.
▸ off<NAME>(name, f): void
Removes a listener for a specific event.
| Name | Type | Description |
|---|---|---|
NAME |
extends keyof ISharedDocEvents<S, T> |
The type of the event name, extending keyof ISharedDocEvents<S, T>. |
| Name | Type | Description |
|---|---|---|
name |
NAME |
The name of the event. |
f |
ISharedDocEvents<S, T>[NAME] |
The event handler function to remove. |
void
▸ on<NAME>(name, f): ISharedDocEvents<S, T>[NAME]
Registers a listener for a specific event.
| Name | Type | Description |
|---|---|---|
NAME |
extends keyof ISharedDocEvents<S, T> |
The type of the event name, extending keyof ISharedDocEvents<S, T>. |
| Name | Type | Description |
|---|---|---|
name |
NAME |
The name of the event. |
f |
ISharedDocEvents<S, T>[NAME] |
The event handler function. |
ISharedDocEvents<S, T>[NAME]
The registered event handler.
▸ once<NAME>(name, f): void
Registers a one-time listener for a specific event.
| Name | Type | Description |
|---|---|---|
NAME |
extends keyof ISharedDocEvents<S, T> |
The type of the event name, extending keyof ISharedDocEvents<S, T>. |
| Name | Type | Description |
|---|---|---|
name |
NAME |
The name of the event. |
f |
ISharedDocEvents<S, T>[NAME] |
The event handler function to call once. |
void
▸ submitOp(component, options?): Promise<void>
Submits an op to the document.
| Name | Type | Description |
|---|---|---|
component |
T |
The op component. |
options? |
IOptions |
- |
Promise<void>
A promise that resolves after the op is submitted.
▸ subscribe(): Promise<void>
Subscribes the snapshot data.
Promise<void>
A promise that resolves after the snapshot is subscribed, the subscribed snapshot data is 'doc.data'.