@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.
property readonly kind: "event"Event observations have no current snapshot.
- interfaceObservationDefinition
-
interface ObservationDefinition<Value>Typed identity imported by publishers and consumers of one observation.
property readonly id: stringStable globally unique id used for registration diagnostics.
property readonly kind: ObservationKindDelivery model that determines whether a current snapshot is available.
property readonly valueType?: ValueCompile-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.
property readonly kind: "state"State observations expose a current snapshot.
- 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 SearErrorPublic error raised when an observation definition or registry lifecycle contract is violated.
constructor ObservationError(code: ObservationErrorCode, message: string, details?: SearErrorDetails): ObservationErrorCreates an observation contract error with structured diagnostic details.
property readonly code: ObservationErrorCodeStable observation-specific error code.
Inherited members 9
Inherited from SearError.
- classObservationRegistry
-
Editor-local typed observation registry exposed to plugins and third-party hosts.
constructor ObservationRegistry(platform?: Platform): ObservationRegistryCreates a registry that reports isolated host listener failures through the platform.
property readonly symbol: typeof symbolstaticDI token for resolving the registry owned by one editor instance.
method destroy(): voidDisposes every active host subscription and removes all registered sources.
method enforceWriteBoundary(assertWrite: (): void, runListener?: ObservationListenerScope, detachValue?: (value: unknown, definition: ObservationDefinition<unknown>): unknown): voidRequires editor command dispatch for source registration changes after assembly.
method getRegisteredObservations(): readonly ObservationDefinition<unknown>[]Returns a stable snapshot of registered observation definitions sorted by id.
method getSnapshot<Value>(definition: StateObservationDefinition<Value>): ValueReturns the current snapshot for a state observation without subscribing.
method has(definition: string | ObservationDefinition<unknown>): booleanReturns whether an observation id is registered in this editor instance.
methodregister register<Value>(definition: EventObservationDefinition<Value>, source: ObservationSource<Value>): (): voidregister<Value>(definition: StateObservationDefinition<Value>, source: StateObservationSource<Value>): (): voidRegisters an event-only source and returns an idempotent registration disposer.
method subscribe<Value>(definition: ObservationDefinition<Value>, listener: (value: Value): void): (): voidSubscribes 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.
constructor SubscriptionManager(platform: Platform): SubscriptionManagerproperty readonly symbol: typeof symbolstaticDI token for resolving SubscriptionManager.
method destroy(): voidReleases resources owned by SubscriptionManager.
method observeResize(target: unknown, callback: (size: { height: number; width: number }): void): (): voidObserves host-view size changes and returns an idempotent disposer.
method track(dispose: (): void): (): voidTracks an arbitrary subscription cleanup function and returns an idempotent disposer.
- interfaceObservationSource
-
interface ObservationSource<Value>Produces future values for an event or state observation.
method subscribe(listener: (value: Value): void): (): voidRegisters 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.
method getSnapshot(): ValueReturns the current immutable state snapshot.
- 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.
No matching API entries.