cache nonDeleted elements (#1626)

This commit is contained in:
David Luzar 2020-05-22 19:15:16 +02:00 committed by GitHub
parent fb897c75a7
commit ce6f2ff88c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,6 +13,7 @@ export interface SceneStateCallbackRemover {
} }
class GlobalScene { class GlobalScene {
private nonDeletedElements: readonly NonDeletedExcalidrawElement[] = [];
private callbacks: Set<SceneStateCallback> = new Set(); private callbacks: Set<SceneStateCallback> = new Set();
constructor(private _elements: readonly ExcalidrawElement[] = []) {} constructor(private _elements: readonly ExcalidrawElement[] = []) {}
@ -22,11 +23,12 @@ class GlobalScene {
} }
getElements(): readonly NonDeletedExcalidrawElement[] { getElements(): readonly NonDeletedExcalidrawElement[] {
return getNonDeletedElements(this._elements); return this.nonDeletedElements;
} }
replaceAllElements(nextElements: readonly ExcalidrawElement[]) { replaceAllElements(nextElements: readonly ExcalidrawElement[]) {
this._elements = nextElements; this._elements = nextElements;
this.nonDeletedElements = getNonDeletedElements(this._elements);
this.informMutation(); this.informMutation();
} }