From b72728bdabf140c77f165b35813595dcaa060eea Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Thu, 23 Sep 2021 23:23:55 +0900 Subject: Create find targets by port connections --- src/background/repositories/FindRepository.ts | 3 +-- .../repositories/ReadyFrameRepository.ts | 22 +++++++++++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) (limited to 'src/background/repositories') 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; - addFrameId(tabId: number, fraemId: number): Promise; + addFrameId(tabId: number, frameId: number): Promise; + + removeFrameId(tabId: number, frameId: number): Promise; getFrameIds(tabId: number): Promise; } @@ -29,12 +31,26 @@ export class ReadyFrameRepositoryImpl implements ReadyFrameRepository { return Promise.resolve(); } - addFrameId(tabId: number, fraemId: number): Promise { + addFrameId(tabId: number, frameId: number): Promise { 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 { + 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(); } -- cgit v1.2.3