@akala/core
Version:
125 lines (124 loc) • 4.62 kB
TypeScript
import { EventEmitter } from "../events/event-emitter.js";
import { Event, type IEventSink, PipeEvent, ReplayEvent } from "../events/shared.js";
import { type Formatter } from "../formatters/common.js";
/**
* A class representing a replayable asynchronous event.
* @template T - The type of the event arguments.
* @template TReturnType - The return type of the event.
*/
export declare class ReplayAsyncEvent<T extends unknown[], TReturnType> extends ReplayEvent<T, Promise<TReturnType>> {
/**
* Creates an instance of ReplayAsyncEvent.
* @param {number} bufferLength - The length of the buffer.
* @param {number} maxListeners - The maximum number of listeners.
* @param {function} combineReturnTypes - A function to combine the return types.
*/
constructor(bufferLength: number, maxListeners: number, combineReturnTypes: Event<T, TReturnType>['combineReturnTypes']);
}
/**
* A class representing a valued event.
* @template T - The type of the event arguments.
* @template TReturnType - The return type of the event.
* @template TOptions - The options for the event.
*/
export declare class ValuedEvent<T extends unknown[], TReturnType, TOptions extends {
once?: boolean;
}> implements IEventSink<T, TReturnType, TOptions> {
private value;
/**
* Creates an instance of ValuedEvent.
* @param {T} value - The value of the event.
*/
constructor(value: T);
hasListeners: boolean;
maxListeners: number;
/**
* Adds a listener to the event.
* @param {function} listener - The listener function.
* @returns {function} A function to remove the listener.
*/
addListener(listener: (...args: T) => void): () => boolean;
/**
* Removes a listener from the event.
* @returns {boolean} Whether the listener was removed.
*/
removeListener(): boolean;
/**
* Disposes of the event.
*/
[Symbol.dispose](): void;
}
/**
* Creates a valued event.
* @template T - The type of the event arguments.
* @param {...T} args - The event arguments.
* @returns {ValuedEvent} The valued event.
*/
export declare function of<T extends unknown[]>(...args: T): ValuedEvent<T, unknown, {
once?: boolean;
}>;
/**
* A class representing a debounce event.
* @template T - The type of the event arguments.
* @template TOptions - The options for the event.
*/
export declare class DebounceEvent<T extends unknown[], TOptions extends {
once?: boolean;
}> extends PipeEvent<T, T, void, TOptions> {
private duration;
/**
* Creates an instance of DebounceEvent.
* @param {IEventSink} source - The source event sink.
* @param {number} duration - The debounce duration.
*/
constructor(source: IEventSink<T, void, TOptions>, duration: number);
/**
* Subscribes to the source event if required.
*/
protected subscribeToSourceIfRequired(): void;
}
/**
* Creates a debounce event.
* @template T - The type of the event arguments.
* @template TOptions - The options for the event.
* @param {IEventSink} source - The source event sink.
* @param {number} duration - The debounce duration.
* @returns {DebounceEvent} The debounce event.
*/
export declare function debounce<T extends unknown[], TOptions extends {
once?: boolean;
}>(source: IEventSink<T, void, TOptions>, duration: number): DebounceEvent<T, TOptions>;
/**
* Creates a pipe event.
* @template T - The type of the event arguments.
* @template U - The type of the mapped event arguments.
* @template TOptions - The options for the event.
* @param {IEventSink} source - The source event sink.
* @param {function} map - The mapping function.
* @returns {PipeEvent} The pipe event.
*/
export declare function pipe<T extends unknown[], U extends unknown[], TOptions extends {
once?: boolean;
}>(source: IEventSink<T, void, TOptions>, map: (...args: T) => U): PipeEvent<T, U, void, TOptions>;
export type Watcher = EventEmitter<{
'change': Event<[source?: object]>;
}>;
/**
* An abstract class representing a watcher formatter.
* @template T - The type of the formatted value.
*/
export declare abstract class WatcherFormatter<T = void> implements Formatter<T> {
protected readonly watcher?: Watcher;
/**
* Creates an instance of WatcherFormatter.
* @param {Watcher} [watcher] - The watcher.
*/
constructor(watcher?: Watcher);
/**
* Formats a value.
* @param {unknown} value - The value to format.
* @returns {T} The formatted value.
*/
abstract format(value: unknown): T;
}
export declare const watcher: unique symbol;