@@ -4,26 +4,30 @@ export class Favicon extends ContentFeature {
4
4
/** @type {undefined|number } */
5
5
#debounce = undefined ;
6
6
init ( ) {
7
- window . addEventListener ( 'DOMContentLoaded' , ( ) => this . setup ( ) ) ;
7
+ window . addEventListener ( 'DOMContentLoaded' , ( ) => {
8
+ // send once, immediately
9
+ this . send ( ) ;
10
+
11
+ // then optionally watch for changes
12
+ this . monitorChanges ( ) ;
13
+ } ) ;
8
14
}
9
15
10
- setup ( ) {
11
- this . send ( ) ;
16
+ monitorChanges ( ) {
17
+ // if there was an explicit opt-out, do nothing
18
+ if ( this . getFeatureSetting ( 'monitor' ) === false ) return ;
12
19
13
- // was there an explicit opt-out?
14
- if ( this . getFeatureSetting ( 'monitor' ) !== false ) {
15
- monitor ( ( ) => this . send ( ) ) ;
16
- }
20
+ // otherwise, monitor and send updates
21
+ monitor ( ( ) => {
22
+ clearTimeout ( this . #debounce) ;
23
+ const id = setTimeout ( ( ) => this . send ( ) , 100 ) ;
24
+ this . #debounce = /** @type {any } */ ( id ) ;
25
+ } ) ;
17
26
}
18
27
19
28
send ( ) {
20
- clearTimeout ( this . #debounce) ;
21
- const id = setTimeout ( ( ) => {
22
- const favicons = getFaviconList ( ) ;
23
- this . notify ( 'faviconFound' , { favicons, documentUrl : document . URL } ) ;
24
- } , 100 ) ;
25
- // todo(shane): fix this timer id type
26
- this . #debounce = /** @type {any } */ ( id ) ;
29
+ const favicons = getFaviconList ( ) ;
30
+ this . notify ( 'faviconFound' , { favicons, documentUrl : document . URL } ) ;
27
31
}
28
32
}
29
33
0 commit comments