From 003742ec51aa7aea9214442bc0b611e2eb5eaf6e Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Fri, 12 Oct 2018 10:14:33 +0900 Subject: Support global marks which select a tab --- src/background/repositories/mark.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/background/repositories/mark.js (limited to 'src/background/repositories') 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) || {}; + } +} + -- cgit v1.2.3