From fc3407cabd7ad34d655c72eef73d93a1f85b9712 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Wed, 25 Mar 2026 13:47:49 +0100 Subject: [PATCH] Use optional chaining rather than `typeof` checks when invoking the `AnnotationStorage` callbacks This is a little bit shorter, and it should be fine considering that in the API there are no `typeof` checks when invoking user-provided callbacks (see e.g. `onPassword` and `onProgress`). --- src/display/annotation_storage.js | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/src/display/annotation_storage.js b/src/display/annotation_storage.js index e0736b301..312643362 100644 --- a/src/display/annotation_storage.js +++ b/src/display/annotation_storage.js @@ -100,14 +100,10 @@ class AnnotationStorage { this.resetModified(); } - if (typeof this.onAnnotationEditor === "function") { - for (const value of this.#storage.values()) { - if (value instanceof AnnotationEditor) { - return; - } - } - this.onAnnotationEditor(null); + if (this.#storage.values().some(v => v instanceof AnnotationEditor)) { + return; } + this.onAnnotationEditor?.(null); } /** @@ -135,9 +131,7 @@ class AnnotationStorage { if (value instanceof AnnotationEditor) { (this.#editorsMap ||= new Map()).set(value.annotationElementId, value); - if (typeof this.onAnnotationEditor === "function") { - this.onAnnotationEditor(value.constructor._type); - } + this.onAnnotationEditor?.(value.constructor._type); } } @@ -157,18 +151,14 @@ class AnnotationStorage { #setModified() { if (!this.#modified) { this.#modified = true; - if (typeof this.onSetModified === "function") { - this.onSetModified(); - } + this.onSetModified?.(); } } resetModified() { if (this.#modified) { this.#modified = false; - if (typeof this.onResetModified === "function") { - this.onResetModified(); - } + this.onResetModified?.(); } }