Skip to content

Commit

Permalink
infra(lint-fixes) for index and prefetch
Browse files Browse the repository at this point in the history
  • Loading branch information
addyosmani committed Dec 6, 2018
1 parent 6336333 commit c8c47f8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
19 changes: 9 additions & 10 deletions src/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ import requestIdleCallback from './request-idle-callback.mjs';
* @return {Promise} resolving with list of URLs found
*/
function fetchInViewportLinks(el, options) {
const links = Array.from(el.querySelectorAll('a'));
const links = Array.from(el.querySelectorAll('a'));
const observer = new IntersectionObserver(entries => {
const urls = entries
.filter(entry => entry.isIntersecting)
.map(entry => {
observer.unobserve(entry.target);
return entry.target.href;
});
.filter(entry => entry.isIntersecting)
.map(entry => {
observer.unobserve(entry.target);
return entry.target.href;
});
// prefetch() maintains a list of in-memory URLs
// previously fetched so we don't attempt a refetch
prefetchURLs(urls, options.priority);
Expand Down Expand Up @@ -68,17 +68,16 @@ function prefetchURLs(urls, priority) {
* @param {string} options.priority - Attempt to fetch with higher priority (low or high)
* @param {Number} options.timeout - Timeout after which prefetching will occur
* @param {function} options.timeoutFn - Custom timeout function
* @return {Object} Promise
*/
export default function (options) {
options = {
... {
...{
priority: 'low',
timeout: 2000,
timeoutFn: requestIdleCallback,
el: document
el: document,
},
...options
...options,
};

options.timeoutFn(() => {
Expand Down
4 changes: 2 additions & 2 deletions src/prefetch.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ async function prefetcher(url, priority) {

if ('connection' in navigator) {
// Don't prefetch if the user is on 2G..
if ((navigator.connection.effectiveType || "").includes("2g")) {
if ((navigator.connection.effectiveType || '').includes('2g')) {
return;
}
// Don't prefetch if Save-Data is enabled..
Expand All @@ -140,7 +140,7 @@ async function prefetcher(url, priority) {
await supportedPrefetchStrategy(url);
};
preFetched[url] = true;
} catch(e) {
} catch (e) {
// Wanna do something?
}
};
Expand Down

0 comments on commit c8c47f8

Please sign in to comment.