aboutsummaryrefslogtreecommitdiff
path: root/src/background/repositories/MarkRepository.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/background/repositories/MarkRepository.js')
-rw-r--r--src/background/repositories/MarkRepository.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/background/repositories/MarkRepository.js b/src/background/repositories/MarkRepository.js
new file mode 100644
index 0000000..282c712
--- /dev/null
+++ b/src/background/repositories/MarkRepository.js
@@ -0,0 +1,33 @@
+import MemoryStorage from '../infrastructures/MemoryStorage';
+import GlobalMark from '../domains/GlobalMark';
+
+const MARK_KEY = 'mark';
+
+export default class MarkRepository {
+ constructor() {
+ this.cache = new MemoryStorage();
+ }
+
+ getMark(key) {
+ let marks = this.getOrEmptyMarks();
+ let data = marks[key];
+ if (!data) {
+ return Promise.resolve(undefined);
+ }
+ let mark = new GlobalMark(data.tabId, data.url, data.x, data.y);
+ return Promise.resolve(mark);
+ }
+
+ setMark(key, mark) {
+ let marks = this.getOrEmptyMarks();
+ marks[key] = { tabId: mark.tabId, url: mark.url, x: mark.x, y: mark.y };
+ this.cache.set(MARK_KEY, marks);
+
+ return Promise.resolve();
+ }
+
+ getOrEmptyMarks() {
+ return this.cache.get(MARK_KEY) || {};
+ }
+}
+