← All packages

@searsuite/sear-foundation-subscription

Idempotent subscription ownership and reverse-order disposal utilities.

Define observations

interfaceEventObservationDefinition
interface EventObservationDefinition<Value> extends ObservationDefinition<Value>

Definition for an event-only observation stream.

propertyreadonly kind: "event"

Event observations have no current snapshot.

Inherited members 2

Inherited from ObservationDefinition.

interfaceObservationDefinition
interface ObservationDefinition<Value>

Typed identity imported by publishers and consumers of one observation.

propertyreadonly id: string

Stable globally unique id used for registration diagnostics.

propertyreadonly kind: ObservationKind

Delivery model that determines whether a current snapshot is available.

propertyreadonly valueType?: Value

Compile-time value carrier; never populated at runtime.

interfaceStateObservationDefinition
interface StateObservationDefinition<Value> extends ObservationDefinition<Value>

Definition for an observation stream backed by a current state snapshot.

propertyreadonly kind: "state"

State observations expose a current snapshot.

Inherited members 2

Inherited from ObservationDefinition.

typeObservationKind
type ObservationKind = typeof ObservationKind[keyof typeof ObservationKind] ObservationKind: { Event: "event"; State: "state" }

Supported observation delivery models.

functiondefineEventObservation
defineEventObservation<Value>(id: string): EventObservationDefinition<Value>

Creates a typed identity for an event-only observation stream.

functiondefineStateObservation
defineStateObservation<Value>(id: string): StateObservationDefinition<Value>

Creates a typed identity for a snapshot-backed state observation stream.

Register and subscribe

classObservationError
class ObservationError extends SearError

Public error raised when an observation definition or registry lifecycle contract is violated.

constructorObservationError(code: ObservationErrorCode, message: string, details?: SearErrorDetails): ObservationError

Creates an observation contract error with structured diagnostic details.

propertyreadonly code: ObservationErrorCode

Stable observation-specific error code.

Inherited members 9

Inherited from SearError.

classObservationRegistry

Editor-local typed observation registry exposed to plugins and third-party hosts.

constructorObservationRegistry(platform?: Platform): ObservationRegistry

Creates a registry that reports isolated host listener failures through the platform.

propertyreadonly symbol: typeof symbolstatic

DI token for resolving the registry owned by one editor instance.

methoddestroy(): void

Disposes every active host subscription and removes all registered sources.

methodenforceWriteBoundary(assertWrite: (): void, runListener?: ObservationListenerScope, detachValue?: (value: unknown, definition: ObservationDefinition<unknown>): unknown): void

Requires editor command dispatch for source registration changes after assembly.

methodgetRegisteredObservations(): readonly ObservationDefinition<unknown>[]

Returns a stable snapshot of registered observation definitions sorted by id.

methodgetSnapshot<Value>(definition: StateObservationDefinition<Value>): Value

Returns the current snapshot for a state observation without subscribing.

methodhas(definition: string | ObservationDefinition<unknown>): boolean

Returns whether an observation id is registered in this editor instance.

methodregister
register<Value>(definition: EventObservationDefinition<Value>, source: ObservationSource<Value>): (): void register<Value>(definition: StateObservationDefinition<Value>, source: StateObservationSource<Value>): (): void

Registers an event-only source and returns an idempotent registration disposer.

methodsubscribe<Value>(definition: ObservationDefinition<Value>, listener: (value: Value): void): (): void

Subscribes to a typed observation and returns an idempotent disposer.

classSubscriptionManager

Owns cancellable subscriptions for one consumer instance.

It centralizes disposal so viewport, DPR, visibility, network, and other observers do not each need a dedicated cleanup field.

constructorSubscriptionManager(platform: Platform): SubscriptionManager
propertyreadonly symbol: typeof symbolstatic

DI token for resolving SubscriptionManager.

methoddestroy(): void

Releases resources owned by SubscriptionManager.

methodobserveResize(target: unknown, callback: (size: { height: number; width: number }): void): (): void

Observes host-view size changes and returns an idempotent disposer.

methodtrack(dispose: (): void): (): void

Tracks an arbitrary subscription cleanup function and returns an idempotent disposer.

interfaceObservationSource
interface ObservationSource<Value>

Produces future values for an event or state observation.

methodsubscribe(listener: (value: Value): void): (): void

Registers a listener for future values and returns an idempotent disposer.

interfaceStateObservationSource
interface StateObservationSource<Value> extends ObservationSource<Value>

Produces a current snapshot plus future values for a state observation.

methodgetSnapshot(): Value

Returns the current immutable state snapshot.

Inherited members 1

Inherited from ObservationSource.

typeObservationErrorCode
type ObservationErrorCode = typeof ObservationErrorCode[keyof typeof ObservationErrorCode] ObservationErrorCode: { AlreadyRegistered: "SEAR_OBSERVATION_ALREADY_REGISTERED"; DefinitionMismatch: "SEAR_OBSERVATION_DEFINITION_MISMATCH"; InvalidDefinition: "SEAR_OBSERVATION_INVALID_DEFINITION"; NotRegistered: "SEAR_OBSERVATION_NOT_REGISTERED"; RegistryDestroyed: "SEAR_OBSERVATION_REGISTRY_DESTROYED"; SnapshotUnavailable: "SEAR_OBSERVATION_SNAPSHOT_UNAVAILABLE" }

Machine-readable observation error code.