File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed
browser-extension/src/lib Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -13,15 +13,23 @@ export interface EnhancedTextarea<T extends CommentSpot = CommentSpot> {
1313export class EnhancerRegistry {
1414 private enhancers = new Set < CommentEnhancer > ( )
1515 private preparedEnhancers = new Set < CommentEnhancer > ( )
16+ private byType = new Map < string , CommentEnhancer > ( )
1617
1718 constructor ( ) {
1819 // Register all available handlers
1920 this . register ( new GitHubIssueAddCommentEnhancer ( ) )
2021 this . register ( new GitHubPRAddCommentEnhancer ( ) )
2122 }
2223
23- private register < T extends CommentSpot > ( handler : CommentEnhancer < T > ) : void {
24- this . enhancers . add ( handler )
24+ private register < T extends CommentSpot > ( enhancer : CommentEnhancer < T > ) : void {
25+ this . enhancers . add ( enhancer )
26+ for ( const spotType in enhancer . forSpotTypes ( ) ) {
27+ this . byType . set ( spotType , enhancer )
28+ }
29+ }
30+
31+ enhancerFor < T extends CommentSpot > ( spot : T ) : CommentEnhancer < T > {
32+ return this . byType . get ( spot . type ) ! as CommentEnhancer < T >
2533 }
2634
2735 tryToEnhance ( textarea : HTMLTextAreaElement ) : EnhancedTextarea | null {
You can’t perform that action at this time.
0 commit comments