-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12106 from calixteman/storage
Add an annotation storage in order to save annotation data in acroforms
- Loading branch information
Showing
13 changed files
with
152 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* Copyright 2020 Mozilla Foundation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
class AnnotationStorage { | ||
constructor() { | ||
this._storage = {}; | ||
} | ||
|
||
/** | ||
* Get the value for a given key if it exists | ||
* or store and return the default value | ||
* | ||
* @public | ||
* @memberof AnnotationStorage | ||
* @param {string} key | ||
* @param {Object} defaultValue | ||
* @returns {Object} | ||
*/ | ||
getOrCreateValue(key, defaultValue) { | ||
if (key in this._storage) { | ||
return this._storage[key]; | ||
} | ||
|
||
this._storage[key] = defaultValue; | ||
return defaultValue; | ||
} | ||
|
||
/** | ||
* Set the value for a given key | ||
* | ||
* @public | ||
* @memberof AnnotationStorage | ||
* @param {string} key | ||
* @param {Object} value | ||
*/ | ||
setValue(key, value) { | ||
this._storage[key] = value; | ||
} | ||
|
||
getAll() { | ||
return this._storage; | ||
} | ||
} | ||
|
||
export { AnnotationStorage }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* Copyright 2020 Mozilla Foundation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { AnnotationStorage } from "../../src/display/annotation_storage.js"; | ||
|
||
describe("AnnotationStorage", function () { | ||
describe("GetOrCreateValue", function () { | ||
it("should get and set a new value in the annotation storage", function (done) { | ||
const annotationStorage = new AnnotationStorage(); | ||
let value = annotationStorage.getOrCreateValue("123A", "hello world"); | ||
expect(value).toEqual("hello world"); | ||
|
||
// the second argument is the default value to use | ||
// if the key isn't in the storage | ||
value = annotationStorage.getOrCreateValue("123A", "an other string"); | ||
expect(value).toEqual("hello world"); | ||
done(); | ||
}); | ||
}); | ||
|
||
describe("SetValue", function () { | ||
it("should set a new value in the annotation storage", function (done) { | ||
const annotationStorage = new AnnotationStorage(); | ||
annotationStorage.setValue("123A", "an other string"); | ||
const value = annotationStorage.getAll()["123A"]; | ||
expect(value).toEqual("an other string"); | ||
done(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters