From fe5f7358152e9cf122434ee117d06ba80d77ba5a Mon Sep 17 00:00:00 2001 From: Luke Edwards Date: Thu, 13 Dec 2018 18:41:20 -0800 Subject: [PATCH] golf: inline `options` defaults; - 672 gz / 558 br --- src/index.mjs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/index.mjs b/src/index.mjs index ed5fb0f6..ee45579c 100644 --- a/src/index.mjs +++ b/src/index.mjs @@ -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}); }