aboutsummaryrefslogtreecommitdiff
path: root/src/background/repositories
diff options
context:
space:
mode:
Diffstat (limited to 'src/background/repositories')
-rw-r--r--src/background/repositories/ReadyFrameRepository.ts49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/background/repositories/ReadyFrameRepository.ts b/src/background/repositories/ReadyFrameRepository.ts
new file mode 100644
index 0000000..725f604
--- /dev/null
+++ b/src/background/repositories/ReadyFrameRepository.ts
@@ -0,0 +1,49 @@
+import MemoryStorage from "../infrastructures/MemoryStorage";
+
+const REPOSITORY_KEY = "readyFrameRepository";
+
+type State = { [tabId: number]: number[] };
+
+export default interface ReadyFrameRepository {
+ clearFrameIds(tabId: number): Promise<void>;
+
+ addFrameId(tabId: number, fraemId: number): Promise<void>;
+
+ getFrameIds(tabId: number): Promise<number[] | undefined>;
+}
+
+export class ReadyFrameRepositoryImpl implements ReadyFrameRepository {
+ private cache: MemoryStorage;
+
+ constructor() {
+ this.cache = new MemoryStorage();
+ }
+
+ clearFrameIds(tabId: number): Promise<void> {
+ let state: State | undefined = this.cache.get(REPOSITORY_KEY);
+ if (typeof state === "undefined") {
+ state = {};
+ }
+ delete state[tabId];
+ this.cache.set(REPOSITORY_KEY, state);
+ return Promise.resolve();
+ }
+
+ addFrameId(tabId: number, fraemId: number): Promise<void> {
+ let state: State | undefined = this.cache.get(REPOSITORY_KEY);
+ if (typeof state === "undefined") {
+ state = {};
+ }
+ state[tabId] = (state[tabId] || []).concat(fraemId);
+ this.cache.set(REPOSITORY_KEY, state);
+ return Promise.resolve();
+ }
+
+ getFrameIds(tabId: number): Promise<number[] | undefined> {
+ const state: State | undefined = this.cache.get(REPOSITORY_KEY);
+ if (typeof state === "undefined") {
+ return Promise.resolve(undefined);
+ }
+ return Promise.resolve(state[tabId]);
+ }
+}