Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | /** Removes a subscription or resource. Calling it more than once is safe. @public */
export type Unsubscribe = () => void;
/** Receives the latest immutable controller snapshot. @public */
export type SnapshotListener<TSnapshot> = (snapshot: Readonly<TSnapshot>) => void;
/**
* Shared lifecycle implemented by every runtime controller.
*
* @remarks
* `destroy()` is idempotent. After destruction, commands are no-ops, subscriptions return an
* inert unsubscribe function, and `getSnapshot()` keeps returning the final snapshot.
* @public
*/
export interface RuntimeController<TSnapshot> {
/** Returns the current immutable snapshot, including after destruction. */
getSnapshot(): Readonly<TSnapshot>;
/** Subscribes to future distinct snapshots without synchronously invoking the listener. */
subscribe(listener: SnapshotListener<TSnapshot>): Unsubscribe;
/** Releases owned listeners, timers, observers, focus scopes, and subscriptions. */
destroy(): void;
}
/** Describes why a controller state transition occurred. @public */
export interface ChangeDetails<TReason extends string> {
/** Closed union member identifying the cause of the transition. */
readonly reason: TReason;
/** Original platform event when the transition came from user interaction. */
readonly event?: Event;
}
/** Configuration shared by controlled and uncontrolled values. @public */
export interface ControllableValueOptions<TValue, TReason extends string> {
/** Initial value used only in uncontrolled mode. */
readonly defaultValue: TValue;
/** Reads the consumer-owned value. Its presence enables controlled mode. */
readonly getValue?: () => TValue;
/** Receives every accepted value request and its typed cause. */
readonly onValueChange?: (value: TValue, details: ChangeDetails<TReason>) => void;
/** Subscribes to consumer-owned value changes in controlled mode. */
readonly subscribeValue?: (listener: () => void) => Unsubscribe;
}
/** Function that may veto a cancellable runtime lifecycle event. @public */
export type RuntimeEventListener<TPayload> = (event: RuntimeEvent<TPayload>) => void;
/** Typed cancellable lifecycle event delivered by runtime controllers. @public */
export interface RuntimeEvent<TPayload> {
/** Event payload supplied by the controller. */
readonly detail: Readonly<TPayload>;
/** Whether a listener cancelled the pending transition. */
readonly defaultPrevented: boolean;
/** Cancels a `before*` transition. Calling this for informational events is harmless. */
preventDefault(): void;
}
/** Uniform typed event surface implemented by interactive controllers. @public */
export interface RuntimeEventSource<TEvents extends object> {
/** Registers a listener and returns an idempotent unsubscribe function. */
on<TKey extends keyof TEvents>(
type: TKey,
listener: RuntimeEventListener<TEvents[TKey]>,
): Unsubscribe;
/** Removes a previously registered listener. */
off<TKey extends keyof TEvents>(type: TKey, listener: RuntimeEventListener<TEvents[TKey]>): void;
/** Registers a listener that is automatically removed after its first call. */
once<TKey extends keyof TEvents>(
type: TKey,
listener: RuntimeEventListener<TEvents[TKey]>,
): Unsubscribe;
}
|