From 9428c9f6edcce152cb27f592b973371769988f71 Mon Sep 17 00:00:00 2001 From: krassowski <5832902+krassowski@users.noreply.github.com> Date: Wed, 8 Nov 2023 08:12:57 +0000 Subject: [PATCH] Use throttler to limit the number of updates Using throttler over debouncer proposed in #15109 because debouncer would not show cells progressively during resize until user has stopped resizing. --- .../ui-components/src/components/windowedlist.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/ui-components/src/components/windowedlist.ts b/packages/ui-components/src/components/windowedlist.ts index 7afc8d4a193c..4e7ba3e2126a 100644 --- a/packages/ui-components/src/components/windowedlist.ts +++ b/packages/ui-components/src/components/windowedlist.ts @@ -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'; @@ -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); @@ -727,6 +729,14 @@ export class WindowedList< return this._viewModel; } + /** + * Dispose the windowed list. + */ + dispose(): void { + this._updater.dispose(); + super.dispose(); + } + /** * Callback on event. * @@ -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); } @@ -1118,6 +1128,7 @@ export class WindowedList< private _scrollRepaint: number | null; private _scrollToItem: [number, WindowedList.ScrollToAlign] | null; private _scrollUpdateWasRequested: boolean; + private _updater: Throttler; } /**