aboutsummaryrefslogtreecommitdiff
path: root/src/background/infrastructures/memory-storage.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/background/infrastructures/memory-storage.js')
-rw-r--r--src/background/infrastructures/memory-storage.js19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/background/infrastructures/memory-storage.js b/src/background/infrastructures/memory-storage.js
new file mode 100644
index 0000000..3a7e4f2
--- /dev/null
+++ b/src/background/infrastructures/memory-storage.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);
+ }
+}