Skip to content

Commit

Permalink
Use throttler to limit the number of updates
Browse files Browse the repository at this point in the history
Using throttler over debouncer proposed in jupyterlab#15109 because
debouncer would not show cells progressively during resize
until user has stopped resizing.
  • Loading branch information
krassowski committed Nov 8, 2023
1 parent 842c6a7 commit 9428c9f
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/ui-components/src/components/windowedlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { ArrayExt } from '@lumino/algorithm';
import { PromiseDelegate } from '@lumino/coreutils';
import { IDisposable } from '@lumino/disposable';
import { Message, MessageLoop } from '@lumino/messaging';
import { Throttler } from '@lumino/polling';
import { ISignal, Signal } from '@lumino/signaling';
import { PanelLayout, Widget } from '@lumino/widgets';

Expand Down Expand Up @@ -688,6 +689,7 @@ export class WindowedList<
this._scrollToItem = null;
this._scrollRepaint = null;
this._scrollUpdateWasRequested = false;
this._updater = new Throttler(() => this.update(), 50);
this._resizeObserver = null;

this._viewModel.stateChanged.connect(this.onStateChanged, this);
Expand Down Expand Up @@ -727,6 +729,14 @@ export class WindowedList<
return this._viewModel;
}

/**
* Dispose the windowed list.
*/
dispose(): void {
this._updater.dispose();
super.dispose();
}

/**
* Callback on event.
*
Expand Down Expand Up @@ -884,7 +894,7 @@ export class WindowedList<
this.viewModel.height =
msg.height >= 0 ? msg.height : this.node.getBoundingClientRect().height;
if (this.viewModel.height !== previousHeight) {
this.update();
void this._updater.invoke();
}
super.onResize(msg);
}
Expand Down Expand Up @@ -1118,6 +1128,7 @@ export class WindowedList<
private _scrollRepaint: number | null;
private _scrollToItem: [number, WindowedList.ScrollToAlign] | null;
private _scrollUpdateWasRequested: boolean;
private _updater: Throttler;
}

/**
Expand Down

0 comments on commit 9428c9f

Please sign in to comment.