Skip to content

Commit

Permalink
Revert "add Event.debouncedListener as replacement for debounce, m…
Browse files Browse the repository at this point in the history
…icrosoft#123487"

This reverts commit f41273c.
  • Loading branch information
jrieken committed Feb 11, 2022
1 parent 854309e commit 63cb496
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 35 deletions.
35 changes: 3 additions & 32 deletions src/vs/base/common/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,45 +145,16 @@ export namespace Event {
return emitter.event;
}

export function debouncedListener<T, O = T>(event: Event<T>, listener: (data: O) => any, merge: (last: O | undefined, event: T) => O, delay: number = 100, leading: boolean = false): IDisposable {

let output: O | undefined = undefined;
let handle: any = undefined;
let numDebouncedCalls = 0;

return event(cur => {
numDebouncedCalls++;
output = merge(output, cur);

if (leading && !handle) {
listener(output);
output = undefined;
}

clearTimeout(handle);
handle = setTimeout(() => {
const _output = output;
output = undefined;
handle = undefined;
if (!leading || numDebouncedCalls > 1) {
listener(_output!);
}

numDebouncedCalls = 0;
}, delay);
});
}

/**
* @deprecated this leaks memory, {@link debouncedListener} or {@link DebounceEmitter} instead
* @deprecated DO NOT use, this leaks memory
*/
export function debounce<T>(event: Event<T>, merge: (last: T | undefined, event: T) => T, delay?: number, leading?: boolean, leakWarningThreshold?: number, disposable?: DisposableStore): Event<T>;
/**
* @deprecated this leaks memory, {@link debouncedListener} or {@link DebounceEmitter} instead
* @deprecated DO NOT use, this leaks memory
*/
export function debounce<I, O>(event: Event<I>, merge: (last: O | undefined, event: I) => O, delay?: number, leading?: boolean, leakWarningThreshold?: number, disposable?: DisposableStore): Event<O>;
/**
* @deprecated this leaks memory, {@link debouncedListener} or {@link DebounceEmitter} instead
* @deprecated DO NOT use, this leaks memory
*/
export function debounce<I, O>(event: Event<I>, merge: (last: O | undefined, event: I) => O, delay: number = 100, leading = false, leakWarningThreshold?: number, disposable?: DisposableStore): Event<O> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,12 +507,11 @@ class NotebookEditorManager implements IWorkbenchContribution {

// OPEN notebook editor for models that have turned dirty without being visible in an editor
type E = IResolvedNotebookEditorModel;
this._disposables.add(Event.debouncedListener<E, E[]>(
this._disposables.add(Event.debounce<E, E[]>(
this._notebookEditorModelService.onDidChangeDirty,
this._openMissingDirtyNotebookEditors.bind(this),
(last, current) => !last ? [current] : [...last, current],
100
));
)(this._openMissingDirtyNotebookEditors, this));

// CLOSE notebook editor for models that have no more serializer
this._disposables.add(notebookService.onWillRemoveViewType(e => {
Expand Down

0 comments on commit 63cb496

Please sign in to comment.