From b3264328959740503350d2b5b64c255aa3265182 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 11 Mar 2021 16:25:53 +0100 Subject: [PATCH] Simplify the data lookup in the `AnnotationStorage.getValue` method Rather than first checking if data exists before fetching it from storage, we can simply do the lookup directly and then check its value. Note that this follows the same pattern as utilized in the `AnnotationStorage.setValue` method. --- src/display/annotation_storage.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/display/annotation_storage.js b/src/display/annotation_storage.js index 145b3faa9..c8d51d1e5 100644 --- a/src/display/annotation_storage.js +++ b/src/display/annotation_storage.js @@ -33,8 +33,7 @@ class AnnotationStorage { } /** - * Get the value for a given key if it exists - * or return the default value + * Get the value for a given key if it exists, or return the default value. * * @public * @memberof AnnotationStorage @@ -43,11 +42,8 @@ class AnnotationStorage { * @returns {Object} */ getValue(key, defaultValue) { - if (this._storage.has(key)) { - return this._storage.get(key); - } - - return defaultValue; + const obj = this._storage.get(key); + return obj !== undefined ? obj : defaultValue; } /**