Skip to content

Commit d5776bb

Browse files
committed
send the first set immediately
1 parent 0cbe981 commit d5776bb

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

injected/src/features/favicon.js

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,30 @@ export class Favicon extends ContentFeature {
44
/** @type {undefined|number} */
55
#debounce = undefined;
66
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+
});
814
}
915

10-
setup() {
11-
this.send();
16+
monitorChanges() {
17+
// if there was an explicit opt-out, do nothing
18+
if (this.getFeatureSetting('monitor') === false) return;
1219

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+
});
1726
}
1827

1928
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 });
2731
}
2832
}
2933

0 commit comments

Comments
 (0)