Skip to content

Commit 334b601

Browse files
authored
Merge pull request microsoft#167074 from microsoft/tyriar/163572_1
Add docs to some functions in event.ts
2 parents 34e5fb1 + d3022a6 commit 334b601

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

src/vs/base/common/event.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ const _enableSnapshotPotentialLeakWarning = false;
2727
// _enableSnapshotPotentialLeakWarning = Boolean("TRUE"); // causes a linter warning so that it cannot be pushed
2828

2929
/**
30-
* To an event a function with one or zero parameters
31-
* can be subscribed. The event is the subscriber function itself.
30+
* An event with zero or one parameters that can be subscribed to. The event is a function itself.
3231
*/
3332
export interface Event<T> {
3433
(listener: (e: T) => any, thisArgs?: any, disposables?: IDisposable[] | DisposableStore): IDisposable;
@@ -37,7 +36,6 @@ export interface Event<T> {
3736
export namespace Event {
3837
export const None: Event<any> = () => Disposable.None;
3938

40-
4139
function _addLeakageTraceLogic(options: EmitterOptions) {
4240
if (_enableSnapshotPotentialLeakWarning) {
4341
const { onDidAddListener: origListenerDidAdd } = options;
@@ -65,13 +63,18 @@ export namespace Event {
6563
* *NOTE* that this function returns an `Event` and it MUST be called with a `DisposableStore` whenever the returned
6664
* event is accessible to "third parties", e.g the event is a public property. Otherwise a leaked listener on the
6765
* returned event causes this utility to leak a listener on the original event.
66+
*
67+
* @param event The event source for the new event.
68+
* @param disposable A disposable store to add the new EventEmitter to.
6869
*/
6970
export function defer(event: Event<unknown>, disposable?: DisposableStore): Event<void> {
7071
return debounce<unknown, void>(event, () => void 0, 0, undefined, undefined, disposable);
7172
}
7273

7374
/**
7475
* Given an event, returns another event which only fires once.
76+
*
77+
* @param event The event source for the new event.
7578
*/
7679
export function once<T>(event: Event<T>): Event<T> {
7780
return (listener, thisArgs = null, disposables?) => {
@@ -99,9 +102,16 @@ export namespace Event {
99102
}
100103

101104
/**
105+
* Maps an event of one type into an event of another type using a mapping function, similar to how
106+
* `Array.prototype.map` works.
107+
*
102108
* *NOTE* that this function returns an `Event` and it MUST be called with a `DisposableStore` whenever the returned
103109
* event is accessible to "third parties", e.g the event is a public property. Otherwise a leaked listener on the
104110
* returned event causes this utility to leak a listener on the original event.
111+
*
112+
* @param event The event source for the new event.
113+
* @param map The mapping function.
114+
* @param disposable A disposable store to add the new EventEmitter to.
105115
*/
106116
export function map<I, O>(event: Event<I>, map: (i: I) => O, disposable?: DisposableStore): Event<O> {
107117
return snapshot((listener, thisArgs = null, disposables?) => event(i => listener.call(thisArgs, map(i)), null, disposables), disposable);
@@ -278,9 +288,21 @@ export namespace Event {
278288
}
279289

280290
/**
291+
* Splits an event whose parameter is a union type into 2 separate events for each type in the union.
292+
*
281293
* *NOTE* that this function returns an `Event` and it MUST be called with a `DisposableStore` whenever the returned
282294
* event is accessible to "third parties", e.g the event is a public property. Otherwise a leaked listener on the
283295
* returned event causes this utility to leak a listener on the original event.
296+
*
297+
* @example
298+
* ```
299+
* const event = new EventEmitter<number | undefined>().event;
300+
* const [numberEvent, undefinedEvent] = Event.split(event, isUndefined);
301+
* ```
302+
*
303+
* @param event The event source for the new event.
304+
* @param isT A function that determines what event is of the first type.
305+
* @param disposable A disposable store to add the new EventEmitter to.
284306
*/
285307
export function split<T, U>(event: Event<T | U>, isT: (e: T | U) => e is T, disposable?: DisposableStore): [Event<T>, Event<U>] {
286308
return [

0 commit comments

Comments
 (0)