Merge pull request #20975 from Snuffleupagus/AnnotationStorage-rm-typeof-function

Use optional chaining rather than `typeof` checks when invoking the `AnnotationStorage` callbacks
This commit is contained in:
Tim van der Meij 2026-03-26 20:35:24 +01:00 committed by GitHub
commit bf7d25b35c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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?.();
}
}