//#region src/beacon.d.ts /** * A beacon is a lighthouse, holding an observable value that can be subscribed to and emitted from */ declare class Beacon { #private; /** * Is the beacon active? */ get active(): boolean; /** * The observable that can be subscribed to */ get observable(): Observable; /** * The current value */ get value(): Value; constructor(value: Value, options?: BeaconOptions); /** * Destroy the beacon */ destroy(): void; /** * Emit a new value * * @param value Value to set and emit * @param finish Finish the beacon after emitting? _(defaults to `false`)_ */ emit(value: Value, finish?: boolean): void; /** * Emit an error * * @param value Error to emit * @param finish Finish the beacon after emitting? _(defaults to `false`)_ */ error(value: Error, finish?: boolean): void; /** * Finish the beacon */ finish(): void; } /** * Options for Beacon */ type BeaconOptions = { /** * Method for comparing values for equality * * @param first First value * @param second Second value * @returns `true` if the values are equal, otherwise `false` * @default Object.is */ equal?: (first: Value, second: Value) => boolean; }; /** * An observable holds a value and allows observers to subscribe to changes in that value */ declare class Observable { #private; constructor(instance: Beacon, observers: Map, Observer>); /** * Destroy the observable */ destroy(): void; /** * Subscribe to value changes * * @param onNext Callback for when the observable receives a new value * @param onError Callback for when the observable receives an error * @param onComplete Callback for when the observable is completed * @returns Subscription to the observable */ subscribe(onNext: (value: Value) => void, onError?: (error: Error) => void, onComplete?: () => void): Subscription; /** * Subscribe to value changes * * @param observer Observer for changes * @returns Subscription to the observable */ subscribe(observer: Observer): Subscription; } type ObservableState = { beacon: Beacon; closed: boolean; observers: Map, Observer>; }; /** * An observer receives notifications from an observable */ type Observer = { /** * Callback for when the observable is completed */ complete?: () => void; /** * Callback for when the observable receives an error */ error?: (error: Error) => void; /** * Callback for when the observable receives a new value */ next?: (value: Value) => void; }; /** * A subscription represents an active subscription to an observable, holding its state and allowing it to be destroyed or unsubscribed from */ declare class Subscription { #private; constructor(state: ObservableState); /** * Is the subscription closed? */ get closed(): boolean; /** * Destroy the subscription */ destroy(): void; /** * Unsubscribe from its observable */ unsubscribe(): void; } /** * Create a new beacon * * @param value Initial value * @param options Beacon options * @returns Beacon instance */ declare function beacon(value: Value, options?: BeaconOptions): Beacon; //#endregion export { type Beacon, type BeaconOptions, type Observable, type Observer, type Subscription, beacon };