aboutsummaryrefslogtreecommitdiff
path: root/src/background/repositories
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2021-09-23 23:23:55 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2021-09-25 15:53:36 +0900
commitb72728bdabf140c77f165b35813595dcaa060eea (patch)
tree774dc608f28101ac4a0ecce02e458e421b94dcdc /src/background/repositories
parent01242a2f0d174b4bf8b51fd5627edced465757e9 (diff)
Create find targets by port connections
Diffstat (limited to 'src/background/repositories')
-rw-r--r--src/background/repositories/FindRepository.ts3
-rw-r--r--src/background/repositories/ReadyFrameRepository.ts22
2 files changed, 20 insertions, 5 deletions
diff --git a/src/background/repositories/FindRepository.ts b/src/background/repositories/FindRepository.ts
index 46ee390..3492759 100644
--- a/src/background/repositories/FindRepository.ts
+++ b/src/background/repositories/FindRepository.ts
@@ -6,8 +6,7 @@ const FIND_LOCAL_KEYWORD_KEY = "find-local-keyword";
export type FindState = {
keyword: string;
- framePos: number;
- frameIds: number[];
+ frameId: number;
};
export default interface FindRepository {
diff --git a/src/background/repositories/ReadyFrameRepository.ts b/src/background/repositories/ReadyFrameRepository.ts
index 725f604..72ae5a4 100644
--- a/src/background/repositories/ReadyFrameRepository.ts
+++ b/src/background/repositories/ReadyFrameRepository.ts
@@ -7,7 +7,9 @@ type State = { [tabId: number]: number[] };
export default interface ReadyFrameRepository {
clearFrameIds(tabId: number): Promise<void>;
- addFrameId(tabId: number, fraemId: number): Promise<void>;
+ addFrameId(tabId: number, frameId: number): Promise<void>;
+
+ removeFrameId(tabId: number, frameId: number): Promise<void>;
getFrameIds(tabId: number): Promise<number[] | undefined>;
}
@@ -29,12 +31,26 @@ export class ReadyFrameRepositoryImpl implements ReadyFrameRepository {
return Promise.resolve();
}
- addFrameId(tabId: number, fraemId: number): Promise<void> {
+ addFrameId(tabId: number, frameId: number): Promise<void> {
let state: State | undefined = this.cache.get(REPOSITORY_KEY);
if (typeof state === "undefined") {
state = {};
}
- state[tabId] = (state[tabId] || []).concat(fraemId);
+ state[tabId] = (state[tabId] || []).concat(frameId);
+ this.cache.set(REPOSITORY_KEY, state);
+ return Promise.resolve();
+ }
+
+ removeFrameId(tabId: number, frameId: number): Promise<void> {
+ const state: State | undefined = this.cache.get(REPOSITORY_KEY);
+ if (typeof state === "undefined") {
+ return Promise.resolve();
+ }
+ const ids = state[tabId];
+ if (typeof ids === "undefined") {
+ return Promise.resolve();
+ }
+ state[tabId] = ids.filter((id) => id != frameId);
this.cache.set(REPOSITORY_KEY, state);
return Promise.resolve();
}