11import type { CommentDraft , CommentEvent , CommentSpot } from '../lib/enhancer'
2- import { JsonMap } from '../lib/jsonmap'
32import type { GetOpenSpotsResponse , ToBackgroundMessage } from '../lib/messages'
43import {
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- }
2015export 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
2823export 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 }
0 commit comments