import { IDisposable, DisposableStore } from './lifecycle'; import { LinkedList } from './linkedList'; /** * To an event a function with one or zero parameters * can be subscribed. The event is the subscriber function itself. */ export interface Event { (listener: (e: T) => any, thisArgs?: any, disposables?: IDisposable[] | DisposableStore): IDisposable; } export declare namespace Event { const None: Event; /** * Given an event, returns another event which only fires once. */ function once(event: Event): Event; /** * Given an event and a `map` function, returns another event which maps each element * through the mapping function. */ function map(event: Event, map: (i: I) => O): Event; /** * Given an event and an `each` function, returns another identical event and calls * the `each` function per each element. */ function forEach(event: Event, each: (i: I) => void): Event; /** * Given an event and a `filter` function, returns another event which emits those * elements for which the `filter` function returns `true`. */ function filter(event: Event, filter: (e: T) => boolean): Event; function filter(event: Event, filter: (e: T | R) => e is R): Event; /** * Given an event, returns the same event but typed as `Event`. */ function signal(event: Event): Event; /** * Given a collection of events, returns a single event which emits * whenever any of the provided events emit. */ function any(...events: Event[]): Event; function any(...events: Event[]): Event; /** * Given an event and a `merge` function, returns another event which maps each element * and the cumulative result through the `merge` function. Similar to `map`, but with memory. */ function reduce(event: Event, merge: (last: O | undefined, event: I) => O, initial?: O): Event; /** * Given a chain of event processing functions (filter, map, etc), each * function will be invoked per event & per listener. Snapshotting an event * chain allows each function to be invoked just once per event. */ function snapshot(event: Event): Event; /** * Debounces the provided event, given a `merge` function. * * @param event The input event. * @param merge The reducing function. * @param delay The debouncing delay in millis. * @param leading Whether the event should fire in the leading phase of the timeout. * @param leakWarningThreshold The leak warning threshold override. */ function debounce(event: Event, merge: (last: T | undefined, event: T) => T, delay?: number, leading?: boolean, leakWarningThreshold?: number): Event; function debounce(event: Event, merge: (last: O | undefined, event: I) => O, delay?: number, leading?: boolean, leakWarningThreshold?: number): Event; /** * Given an event, it returns another event which fires only once and as soon as * the input event emits. The event data is the number of millis it took for the * event to fire. */ function stopwatch(event: Event): Event; /** * Given an event, it returns another event which fires only when the event * element changes. */ function latch(event: Event): Event; /** * Buffers the provided event until a first listener comes * along, at which point fire all the events at once and * pipe the event from then on. * * ```typescript * const emitter = new Emitter(); * const event = emitter.event; * const bufferedEvent = buffer(event); * * emitter.fire(1); * emitter.fire(2); * emitter.fire(3); * // nothing... * * const listener = bufferedEvent(num => console.log(num)); * // 1, 2, 3 * * emitter.fire(4); * // 4 * ``` */ function buffer(event: Event, nextTick?: boolean, _buffer?: T[]): Event; interface IChainableEvent { event: Event; map(fn: (i: T) => O): IChainableEvent; forEach(fn: (i: T) => void): IChainableEvent; filter(fn: (e: T) => boolean): IChainableEvent; filter(fn: (e: T | R) => e is R): IChainableEvent; reduce(merge: (last: R | undefined, event: T) => R, initial?: R): IChainableEvent; latch(): IChainableEvent; debounce(merge: (last: T | undefined, event: T) => T, delay?: number, leading?: boolean, leakWarningThreshold?: number): IChainableEvent; debounce(merge: (last: R | undefined, event: T) => R, delay?: number, leading?: boolean, leakWarningThreshold?: number): IChainableEvent; on(listener: (e: T) => any, thisArgs?: any, disposables?: IDisposable[] | DisposableStore): IDisposable; once(listener: (e: T) => any, thisArgs?: any, disposables?: IDisposable[]): IDisposable; } function chain(event: Event): IChainableEvent; interface NodeEventEmitter { on(event: string | symbol, listener: Function): unknown; removeListener(event: string | symbol, listener: Function): unknown; } function fromNodeEventEmitter(emitter: NodeEventEmitter, eventName: string, map?: (...args: any[]) => T): Event; interface DOMEventEmitter { addEventListener(event: string | symbol, listener: Function): void; removeEventListener(event: string | symbol, listener: Function): void; } function fromDOMEventEmitter(emitter: DOMEventEmitter, eventName: string, map?: (...args: any[]) => T): Event; function fromPromise(promise: Promise): Event; function toPromise(event: Event): Promise; } type Listener = [(e: T) => void, any] | ((e: T) => void); export interface EmitterOptions { onFirstListenerAdd?: Function; onFirstListenerDidAdd?: Function; onListenerDidAdd?: Function; onLastListenerRemove?: Function; leakWarningThreshold?: number; } export declare function setGlobalLeakWarningThreshold(n: number): IDisposable; /** * The Emitter can be used to expose an Event to the public * to fire it from the insides. * Sample: class Document { private readonly _onDidChange = new Emitter<(value:string)=>any>(); public onDidChange = this._onDidChange.event; // getter-style // get onDidChange(): Event<(value:string)=>any> { // return this._onDidChange.event; // } private _doIt() { //... this._onDidChange.fire(value); } } */ export declare class Emitter { private static readonly _noop; private readonly _options?; private readonly _leakageMon?; private _disposed; private _event?; private _deliveryQueue?; protected _listeners?: LinkedList>; constructor(options?: EmitterOptions); /** * For the public to allow to subscribe * to events from this Emitter */ get event(): Event; /** * To be kept private to fire an event to * subscribers */ fire(event: T): void; dispose(): void; } export declare class PauseableEmitter extends Emitter { private _isPaused; private _eventQueue; private _mergeFn?; constructor(options?: EmitterOptions & { merge?: (input: T[]) => T; }); pause(): void; resume(): void; fire(event: T): void; } export interface IWaitUntil { waitUntil(thenable: Promise): void; } export declare class EventMultiplexer implements IDisposable { private readonly emitter; private hasListeners; private events; constructor(); get event(): Event; add(event: Event): IDisposable; private onFirstListenerAdd; private onLastListenerRemove; private hook; private unhook; dispose(): void; } /** * The EventBufferer is useful in situations in which you want * to delay firing your events during some code. * You can wrap that code and be sure that the event will not * be fired during that wrap. * * ``` * const emitter: Emitter; * const delayer = new EventDelayer(); * const delayedEvent = delayer.wrapEvent(emitter.event); * * delayedEvent(console.log); * * delayer.bufferEvents(() => { * emitter.fire(); // event will not be fired yet * }); * * // event will only be fired at this point * ``` */ export declare class EventBufferer { private buffers; wrapEvent(event: Event): Event; bufferEvents(fn: () => R): R; } /** * A Relay is an event forwarder which functions as a replugabble event pipe. * Once created, you can connect an input event to it and it will simply forward * events from that input event through its own `event` property. The `input` * can be changed at any point in time. */ export declare class Relay implements IDisposable { private listening; private inputEvent; private inputEventListener; private readonly emitter; readonly event: Event; set input(event: Event); dispose(): void; } export {}; //# sourceMappingURL=event.d.ts.map