Skip to content

Commit a8fffaa

Browse files
committed
We can simplify by keying on unique_key like we're supposed to, lol
1 parent e8ca1d6 commit a8fffaa

File tree

3 files changed

+8
-68
lines changed

3 files changed

+8
-68
lines changed

browser-extension/src/entrypoints/background.ts

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { CommentDraft, CommentEvent, CommentSpot } from '../lib/enhancer'
2-
import { JsonMap } from '../lib/jsonmap'
32
import type { GetOpenSpotsResponse, ToBackgroundMessage } from '../lib/messages'
43
import {
54
CLOSE_MESSAGE_PORT,
@@ -13,41 +12,33 @@ export interface Tab {
1312
tabId: number
1413
windowId: number
1514
}
16-
export interface TabAndSpot {
17-
tab: Tab
18-
spot: CommentSpot
19-
}
2015
export interface CommentState {
2116
tab: Tab
2217
spot: CommentSpot
2318
drafts: [number, CommentDraft][]
2419
}
2520

26-
export const openSpots = new JsonMap<TabAndSpot, CommentState>()
21+
export const openSpots = new Map<string, CommentState>()
2722

2823
export function handleCommentEvent(message: CommentEvent, sender: any): boolean {
2924
if (
3025
(message.type === 'ENHANCED' || message.type === 'DESTROYED') &&
3126
sender.tab?.id &&
3227
sender.tab?.windowId
3328
) {
34-
const tab: Tab = {
35-
tabId: sender.tab.id,
36-
windowId: sender.tab.windowId,
37-
}
38-
const tabAndSpot: TabAndSpot = {
39-
spot: message.spot,
40-
tab,
41-
}
4229
if (message.type === 'ENHANCED') {
30+
const tab: Tab = {
31+
tabId: sender.tab.id,
32+
windowId: sender.tab.windowId,
33+
}
4334
const commentState: CommentState = {
4435
drafts: [],
4536
spot: message.spot,
4637
tab,
4738
}
48-
openSpots.set(tabAndSpot, commentState)
39+
openSpots.set(message.spot.unique_key, commentState)
4940
} else if (message.type === 'DESTROYED') {
50-
openSpots.delete(tabAndSpot)
41+
openSpots.delete(message.spot.unique_key)
5142
} else {
5243
throw new Error(`Unhandled comment event type: ${message.type}`)
5344
}

browser-extension/src/lib/jsonmap.ts

Lines changed: 0 additions & 51 deletions
This file was deleted.

browser-extension/tests/background.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe('Background Event Handler', () => {
2828
expect(Array.from(openSpots)).toMatchInlineSnapshot(`
2929
[
3030
[
31-
"{"spot":{"type":"TEST_SPOT","unique_key":"test-key"},"tab":{"tabId":123,"windowId":456}}",
31+
"test-key",
3232
{
3333
"drafts": [],
3434
"spot": {

0 commit comments

Comments
 (0)