Skip to content

Commit

Permalink
Merge pull request #12192 from Snuffleupagus/misc-AnnotationStorage-i…
Browse files Browse the repository at this point in the history
…mprovements

A couple of (small) tweaks of the `AnnotationStorage` (PR 12173 follow-up)
  • Loading branch information
timvandermeij committed Aug 11, 2020
2 parents 7fb01f9 + 4d351ea commit 57c9888
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
19 changes: 13 additions & 6 deletions src/display/annotation_storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
class AnnotationStorage {
constructor() {
this._storage = Object.create(null);
this._storage = new Map();
}

/**
Expand All @@ -32,11 +32,11 @@ class AnnotationStorage {
* @returns {Object}
*/
getOrCreateValue(key, defaultValue) {
if (key in this._storage) {
return this._storage[key];
if (this._storage.has(key)) {
return this._storage.get(key);
}

this._storage[key] = defaultValue;
this._storage.set(key, defaultValue);
return defaultValue;
}

Expand All @@ -49,11 +49,18 @@ class AnnotationStorage {
* @param {Object} value
*/
setValue(key, value) {
this._storage[key] = value;
this._storage.set(key, value);
}

getAll() {
return this._storage;
if (this._storage.size === 0) {
return null;
}
return Object.fromEntries(this._storage);
}

get size() {
return this._storage.size;
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/display/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -632,14 +632,13 @@ class PDFDocumentProxy {
constructor(pdfInfo, transport) {
this._pdfInfo = pdfInfo;
this._transport = transport;
this._annotationStorage = new AnnotationStorage();
}

/**
* @type {AnnotationStorage} Storage for annotation data in forms.
*/
get annotationStorage() {
return this._annotationStorage;
return shadow(this, "annotationStorage", new AnnotationStorage());
}

/**
Expand Down

0 comments on commit 57c9888

Please sign in to comment.