Skip to content

Commit

Permalink
golf: inline options defaults;
Browse files Browse the repository at this point in the history
- 672 gz / 558 br
  • Loading branch information
lukeed committed Dec 14, 2018
1 parent 36cc199 commit fe5f735
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,20 @@ function prefetcher(url) {
* @param {function} options.timeoutFn - Custom timeout function
*/
export default function (options) {
options = Object.assign({
timeout: 2e3,
timeoutFn: requestIdleCallback,
el: document,
}, options);
options = options || {};

observer.priority = !!options.priority;

options.timeoutFn(() => {
(options.timeoutFn || requestIdleCallback)(() => {
// If URLs are given, prefetch them.
if (options.urls) {
options.urls.forEach(prefetcher);
} else {
// If not, find all links and use IntersectionObserver.
Array.from(options.el.querySelectorAll('a'), link => {
Array.from((options.el || document).querySelectorAll('a'), link => {
observer.observe(link);
toPrefetch.add(link.href);
});
}
}, {timeout: options.timeout});
}, {timeout: options.timeout || 2e3});
}

0 comments on commit fe5f735

Please sign in to comment.