From fa5def64cacba0215c4b8b79cc43987e39af7f96 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Fri, 18 Nov 2022 23:17:56 -0800 Subject: [PATCH] Add delay on load. --- packages/mindplot/src/components/Workspace.ts | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/mindplot/src/components/Workspace.ts b/packages/mindplot/src/components/Workspace.ts index 8187f042..adc9854d 100644 --- a/packages/mindplot/src/components/Workspace.ts +++ b/packages/mindplot/src/components/Workspace.ts @@ -37,7 +37,7 @@ class Workspace { private _renderQueue: Element2D[]; - private queueRenderEnabled: boolean; + private _queueRenderEnabled: boolean; constructor(screenManager: ScreenManager, zoom: number, isReadOnly: boolean) { // Create a suitable container ... @@ -103,7 +103,7 @@ class Workspace { } append(shape: Element2D): void { - if (this.queueRenderEnabled) { + if (this._queueRenderEnabled) { this._renderQueue.push(shape); } else { this.appendInternal(shape); @@ -119,20 +119,23 @@ class Workspace { } enableQueueRender(value: boolean): Promise { - this.queueRenderEnabled = value; + this._queueRenderEnabled = value; let result = Promise.resolve(); if (!value) { - result = this.processRenderQueue(this._renderQueue.reverse(), 300); + // eslint-disable-next-line arrow-body-style + result = Workspace.delay(100).then(() => { + return this.processRenderQueue(this._renderQueue.reverse(), 300); + }); } return result; } - private processRenderQueue(renderQueue: Element2D[], batch: number): Promise { - function delay(t: number) { - return new Promise((resolve) => setTimeout(resolve, t)); - } + private static delay(t: number) { + return new Promise((resolve) => setTimeout(resolve, t)); + } + private processRenderQueue(renderQueue: Element2D[], batch: number): Promise { let result: Promise; if (renderQueue.length > 0) { result = new Promise((resolve: (queue: Element2D[]) => void) => { @@ -142,7 +145,7 @@ class Workspace { } resolve(renderQueue); - }).then((queue) => delay(30).then(() => this.processRenderQueue(queue, batch))); + }).then((queue) => Workspace.delay(30).then(() => this.processRenderQueue(queue, batch))); } else { result = Promise.resolve(); }