Skip to content

Commit bf7d25b

Browse files
Merge pull request #20975 from Snuffleupagus/AnnotationStorage-rm-typeof-function
Use optional chaining rather than `typeof` checks when invoking the `AnnotationStorage` callbacks
2 parents f52a50b + fc3407c commit bf7d25b

1 file changed

Lines changed: 6 additions & 16 deletions

File tree

src/display/annotation_storage.js

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,10 @@ class AnnotationStorage {
100100
this.resetModified();
101101
}
102102

103-
if (typeof this.onAnnotationEditor === "function") {
104-
for (const value of this.#storage.values()) {
105-
if (value instanceof AnnotationEditor) {
106-
return;
107-
}
108-
}
109-
this.onAnnotationEditor(null);
103+
if (this.#storage.values().some(v => v instanceof AnnotationEditor)) {
104+
return;
110105
}
106+
this.onAnnotationEditor?.(null);
111107
}
112108

113109
/**
@@ -135,9 +131,7 @@ class AnnotationStorage {
135131

136132
if (value instanceof AnnotationEditor) {
137133
(this.#editorsMap ||= new Map()).set(value.annotationElementId, value);
138-
if (typeof this.onAnnotationEditor === "function") {
139-
this.onAnnotationEditor(value.constructor._type);
140-
}
134+
this.onAnnotationEditor?.(value.constructor._type);
141135
}
142136
}
143137

@@ -157,18 +151,14 @@ class AnnotationStorage {
157151
#setModified() {
158152
if (!this.#modified) {
159153
this.#modified = true;
160-
if (typeof this.onSetModified === "function") {
161-
this.onSetModified();
162-
}
154+
this.onSetModified?.();
163155
}
164156
}
165157

166158
resetModified() {
167159
if (this.#modified) {
168160
this.#modified = false;
169-
if (typeof this.onResetModified === "function") {
170-
this.onResetModified();
171-
}
161+
this.onResetModified?.();
172162
}
173163
}
174164

0 commit comments

Comments
 (0)