Skip to content

Commit fe5f735

Browse files
committed
golf: inline options defaults;
- 672 gz / 558 br
1 parent 36cc199 commit fe5f735

1 file changed

Lines changed: 4 additions & 8 deletions

File tree

src/index.mjs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,24 +52,20 @@ function prefetcher(url) {
5252
* @param {function} options.timeoutFn - Custom timeout function
5353
*/
5454
export default function (options) {
55-
options = Object.assign({
56-
timeout: 2e3,
57-
timeoutFn: requestIdleCallback,
58-
el: document,
59-
}, options);
55+
options = options || {};
6056

6157
observer.priority = !!options.priority;
6258

63-
options.timeoutFn(() => {
59+
(options.timeoutFn || requestIdleCallback)(() => {
6460
// If URLs are given, prefetch them.
6561
if (options.urls) {
6662
options.urls.forEach(prefetcher);
6763
} else {
6864
// If not, find all links and use IntersectionObserver.
69-
Array.from(options.el.querySelectorAll('a'), link => {
65+
Array.from((options.el || document).querySelectorAll('a'), link => {
7066
observer.observe(link);
7167
toPrefetch.add(link.href);
7268
});
7369
}
74-
}, {timeout: options.timeout});
70+
}, {timeout: options.timeout || 2e3});
7571
}

0 commit comments

Comments
 (0)