Skip to main content

Class: DocumentSubscription<T>

A live view of a single document. Holds the current value (undefined once the object is deleted or if it doesn't exist), kept in sync via an initial REST fetch plus SSE events scoped to its resourceKey.

Type Parameters​

Type Parameter
T

Constructors​

new DocumentSubscription()​

new DocumentSubscription<T>(connection, cfg): DocumentSubscription<T>

Internal

Parameters​

ParameterType
connectionRealtimeConnection
cfgDocumentWatchConfig<T>

Returns​

DocumentSubscription<T>

Defined in​

4Players/cortex-typescript-sdk/src/realtime/watch.ts:206

Accessors​

current​

get current(): undefined | T

The latest known value. undefined until the initial fetch resolves, or once deleted.

Returns​

undefined | T

Defined in​

4Players/cortex-typescript-sdk/src/realtime/watch.ts:217

Methods​

onError()​

onError(cb): () => void

Register an error listener.

Parameters​

ParameterType
cbErrorListener

Returns​

Function

A disposer that removes this listener.

Returns​

void

Defined in​

4Players/cortex-typescript-sdk/src/realtime/watch.ts:241


onSnapshot()​

onSnapshot(cb): () => void

Register a snapshot listener. Fires immediately with the current value if the initial fetch has already loaded, then on every change.

Parameters​

ParameterType
cbDocumentSnapshotListener<T>

Returns​

Function

A disposer that removes this listener.

Returns​

void

Defined in​

4Players/cortex-typescript-sdk/src/realtime/watch.ts:226


unsubscribe()​

unsubscribe(): void

Tear down: stop listening and release the shared connection.

Returns​

void

Defined in​

4Players/cortex-typescript-sdk/src/realtime/watch.ts:249