aboutsummaryrefslogtreecommitdiff
path: root/src/background/infrastructures/MemoryStorage.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/background/infrastructures/MemoryStorage.ts')
-rw-r--r--src/background/infrastructures/MemoryStorage.ts19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/background/infrastructures/MemoryStorage.ts b/src/background/infrastructures/MemoryStorage.ts
new file mode 100644
index 0000000..baf9ffa
--- /dev/null
+++ b/src/background/infrastructures/MemoryStorage.ts
@@ -0,0 +1,19 @@
+const db: {[key: string]: any} = {};
+
+export default class MemoryStorage {
+ set(name: string, value: any): void {
+ let data = JSON.stringify(value);
+ if (typeof data === 'undefined') {
+ throw new Error('value is not serializable');
+ }
+ db[name] = data;
+ }
+
+ get(name: string): any {
+ let data = db[name];
+ if (!data) {
+ return undefined;
+ }
+ return JSON.parse(data);
+ }
+}