Revert "add Event.debouncedListener as replacement for debounce, https://github.com/microsoft/vscode/issues/123487"

This reverts commit f41273cd78.
This commit is contained in:
Johannes Rieken 2022-02-11 15:03:19 +01:00
parent 854309e8f2
commit 63cb496df6
No known key found for this signature in database
GPG key ID: 96634B5AF12F8798
2 changed files with 5 additions and 35 deletions

View file

@ -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> {

View file

@ -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 => {