1
1
import type { CommentDraft , CommentEvent , CommentSpot } from '../lib/enhancer'
2
- import { JsonMap } from '../lib/jsonmap'
3
2
import type { GetOpenSpotsResponse , ToBackgroundMessage } from '../lib/messages'
4
3
import {
5
4
CLOSE_MESSAGE_PORT ,
@@ -13,41 +12,33 @@ export interface Tab {
13
12
tabId : number
14
13
windowId : number
15
14
}
16
- export interface TabAndSpot {
17
- tab : Tab
18
- spot : CommentSpot
19
- }
20
15
export interface CommentState {
21
16
tab : Tab
22
17
spot : CommentSpot
23
18
drafts : [ number , CommentDraft ] [ ]
24
19
}
25
20
26
- export const openSpots = new JsonMap < TabAndSpot , CommentState > ( )
21
+ export const openSpots = new Map < string , CommentState > ( )
27
22
28
23
export function handleCommentEvent ( message : CommentEvent , sender : any ) : boolean {
29
24
if (
30
25
( message . type === 'ENHANCED' || message . type === 'DESTROYED' ) &&
31
26
sender . tab ?. id &&
32
27
sender . tab ?. windowId
33
28
) {
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
- }
42
29
if ( message . type === 'ENHANCED' ) {
30
+ const tab : Tab = {
31
+ tabId : sender . tab . id ,
32
+ windowId : sender . tab . windowId ,
33
+ }
43
34
const commentState : CommentState = {
44
35
drafts : [ ] ,
45
36
spot : message . spot ,
46
37
tab,
47
38
}
48
- openSpots . set ( tabAndSpot , commentState )
39
+ openSpots . set ( message . spot . unique_key , commentState )
49
40
} else if ( message . type === 'DESTROYED' ) {
50
- openSpots . delete ( tabAndSpot )
41
+ openSpots . delete ( message . spot . unique_key )
51
42
} else {
52
43
throw new Error ( `Unhandled comment event type: ${ message . type } ` )
53
44
}
0 commit comments