mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-06-26 01:55:48 +02:00
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`).
This commit is contained in:
parent
777251da85
commit
fc3407cabd
@ -100,14 +100,10 @@ class AnnotationStorage {
|
|||||||
this.resetModified();
|
this.resetModified();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof this.onAnnotationEditor === "function") {
|
if (this.#storage.values().some(v => v instanceof AnnotationEditor)) {
|
||||||
for (const value of this.#storage.values()) {
|
return;
|
||||||
if (value instanceof AnnotationEditor) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.onAnnotationEditor(null);
|
|
||||||
}
|
}
|
||||||
|
this.onAnnotationEditor?.(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -135,9 +131,7 @@ class AnnotationStorage {
|
|||||||
|
|
||||||
if (value instanceof AnnotationEditor) {
|
if (value instanceof AnnotationEditor) {
|
||||||
(this.#editorsMap ||= new Map()).set(value.annotationElementId, value);
|
(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() {
|
#setModified() {
|
||||||
if (!this.#modified) {
|
if (!this.#modified) {
|
||||||
this.#modified = true;
|
this.#modified = true;
|
||||||
if (typeof this.onSetModified === "function") {
|
this.onSetModified?.();
|
||||||
this.onSetModified();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resetModified() {
|
resetModified() {
|
||||||
if (this.#modified) {
|
if (this.#modified) {
|
||||||
this.#modified = false;
|
this.#modified = false;
|
||||||
if (typeof this.onResetModified === "function") {
|
this.onResetModified?.();
|
||||||
this.onResetModified();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user