From ce6f2ff88cbb648ff48330a0040ccd3016808f30 Mon Sep 17 00:00:00 2001 From: David Luzar Date: Fri, 22 May 2020 19:15:16 +0200 Subject: [PATCH] cache nonDeleted elements (#1626) --- src/scene/globalScene.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/scene/globalScene.ts b/src/scene/globalScene.ts index 1f521a8c..3be47430 100644 --- a/src/scene/globalScene.ts +++ b/src/scene/globalScene.ts @@ -13,6 +13,7 @@ export interface SceneStateCallbackRemover { } class GlobalScene { + private nonDeletedElements: readonly NonDeletedExcalidrawElement[] = []; private callbacks: Set = new Set(); constructor(private _elements: readonly ExcalidrawElement[] = []) {} @@ -22,11 +23,12 @@ class GlobalScene { } getElements(): readonly NonDeletedExcalidrawElement[] { - return getNonDeletedElements(this._elements); + return this.nonDeletedElements; } replaceAllElements(nextElements: readonly ExcalidrawElement[]) { this._elements = nextElements; + this.nonDeletedElements = getNonDeletedElements(this._elements); this.informMutation(); }