From a26d8a8a1bed48a77e062914c120a23ace7bb8cf Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 24 Feb 2019 20:54:35 +0900 Subject: Capitalize background scripts --- src/background/infrastructures/MemoryStorage.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/background/infrastructures/MemoryStorage.js (limited to 'src/background/infrastructures/MemoryStorage.js') diff --git a/src/background/infrastructures/MemoryStorage.js b/src/background/infrastructures/MemoryStorage.js new file mode 100644 index 0000000..3a7e4f2 --- /dev/null +++ b/src/background/infrastructures/MemoryStorage.js @@ -0,0 +1,19 @@ +const db = {}; + +export default class MemoryStorage { + set(name, value) { + let data = JSON.stringify(value); + if (typeof data === 'undefined') { + throw new Error('value is not serializable'); + } + db[name] = data; + } + + get(name) { + let data = db[name]; + if (!data) { + return undefined; + } + return JSON.parse(data); + } +} -- cgit v1.2.3