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.
This commit is contained in:
Jonas Jenwald 2021-03-11 16:25:53 +01:00
parent a0e584eeb2
commit b326432895

View File

@ -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;
}
/**