Skip to content

Commit

Permalink
fix: revert options inlining;
Browse files Browse the repository at this point in the history
- 689 gz / 561 br
  • Loading branch information
lukeed committed Dec 14, 2018
1 parent fe5f735 commit 194881f
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,25 @@ function prefetcher(url) {
* @param {function} options.timeoutFn - Custom timeout function
*/
export default function (options) {
options = options || {};
options = Object.assign({
timeout: 2e3,
priority: false,
timeoutFn: requestIdleCallback,
el: document,
}, options);

observer.priority = !!options.priority;
observer.priority = options.priority;

(options.timeoutFn || requestIdleCallback)(() => {
options.timeoutFn(() => {
// 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 || document).querySelectorAll('a'), link => {
Array.from(options.el.querySelectorAll('a'), link => {
observer.observe(link);
toPrefetch.add(link.href);
});
}
}, {timeout: options.timeout || 2e3});
}, {timeout: options.timeout});
}

0 comments on commit 194881f

Please sign in to comment.