@@ -27,8 +27,7 @@ const _enableSnapshotPotentialLeakWarning = false;
27
27
// _enableSnapshotPotentialLeakWarning = Boolean("TRUE"); // causes a linter warning so that it cannot be pushed
28
28
29
29
/**
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.
32
31
*/
33
32
export interface Event < T > {
34
33
( listener : ( e : T ) => any , thisArgs ?: any , disposables ?: IDisposable [ ] | DisposableStore ) : IDisposable ;
@@ -37,7 +36,6 @@ export interface Event<T> {
37
36
export namespace Event {
38
37
export const None : Event < any > = ( ) => Disposable . None ;
39
38
40
-
41
39
function _addLeakageTraceLogic ( options : EmitterOptions ) {
42
40
if ( _enableSnapshotPotentialLeakWarning ) {
43
41
const { onDidAddListener : origListenerDidAdd } = options ;
@@ -65,13 +63,18 @@ export namespace Event {
65
63
* *NOTE* that this function returns an `Event` and it MUST be called with a `DisposableStore` whenever the returned
66
64
* event is accessible to "third parties", e.g the event is a public property. Otherwise a leaked listener on the
67
65
* 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.
68
69
*/
69
70
export function defer ( event : Event < unknown > , disposable ?: DisposableStore ) : Event < void > {
70
71
return debounce < unknown , void > ( event , ( ) => void 0 , 0 , undefined , undefined , disposable ) ;
71
72
}
72
73
73
74
/**
74
75
* Given an event, returns another event which only fires once.
76
+ *
77
+ * @param event The event source for the new event.
75
78
*/
76
79
export function once < T > ( event : Event < T > ) : Event < T > {
77
80
return ( listener , thisArgs = null , disposables ?) => {
@@ -99,9 +102,16 @@ export namespace Event {
99
102
}
100
103
101
104
/**
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
+ *
102
108
* *NOTE* that this function returns an `Event` and it MUST be called with a `DisposableStore` whenever the returned
103
109
* event is accessible to "third parties", e.g the event is a public property. Otherwise a leaked listener on the
104
110
* 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.
105
115
*/
106
116
export function map < I , O > ( event : Event < I > , map : ( i : I ) => O , disposable ?: DisposableStore ) : Event < O > {
107
117
return snapshot ( ( listener , thisArgs = null , disposables ?) => event ( i => listener . call ( thisArgs , map ( i ) ) , null , disposables ) , disposable ) ;
@@ -278,9 +288,21 @@ export namespace Event {
278
288
}
279
289
280
290
/**
291
+ * Splits an event whose parameter is a union type into 2 separate events for each type in the union.
292
+ *
281
293
* *NOTE* that this function returns an `Event` and it MUST be called with a `DisposableStore` whenever the returned
282
294
* event is accessible to "third parties", e.g the event is a public property. Otherwise a leaked listener on the
283
295
* 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.
284
306
*/
285
307
export function split < T , U > ( event : Event < T | U > , isT : ( e : T | U ) => e is T , disposable ?: DisposableStore ) : [ Event < T > , Event < U > ] {
286
308
return [
0 commit comments