aboutsummaryrefslogtreecommitdiff
path: root/src/background/repositories
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2018-10-12 10:14:33 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2018-10-12 10:14:33 +0900
commit003742ec51aa7aea9214442bc0b611e2eb5eaf6e (patch)
tree20345e48bd226c1e83a1145721f7ba585a1452aa /src/background/repositories
parent6e6e306275a8ee5632a22b1e30c807bd5ae9cc7e (diff)
Support global marks which select a tab
Diffstat (limited to 'src/background/repositories')
-rw-r--r--src/background/repositories/mark.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/background/repositories/mark.js b/src/background/repositories/mark.js
new file mode 100644
index 0000000..a1f6a16
--- /dev/null
+++ b/src/background/repositories/mark.js
@@ -0,0 +1,33 @@
+import MemoryStorage from '../infrastructures/memory-storage';
+import GlobalMark from 'background/domains/global-mark';
+
+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.x, data.y);
+ return Promise.resolve(mark);
+ }
+
+ setMark(key, mark) {
+ let marks = this.getOrEmptyMarks();
+ marks[key] = { tabId: mark.tabId, x: mark.x, y: mark.y };
+ this.cache.set(MARK_KEY, marks);
+
+ return Promise.resolve();
+ }
+
+ getOrEmptyMarks() {
+ return this.cache.get(MARK_KEY) || {};
+ }
+}
+