Skip to content

Commit

Permalink
golf(breaking): use Boolean for priority option;
Browse files Browse the repository at this point in the history
- is only low vs high
- 832 gz / 673 br
  • Loading branch information
lukeed committed Dec 11, 2018
1 parent 0e569a3 commit e478a47
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ function prefetcher(url) {
* @param {Object} options - Configuration options for quicklink
* @param {Array} options.urls - Array of URLs to prefetch (override)
* @param {Object} options.el - DOM element to prefetch in-viewport links of
* @param {string} options.priority - Attempt to fetch with higher priority (low or high)
* @param {Boolean} options.priority - Attempt higher priority fetch (low or high)
* @param {Number} options.timeout - Timeout after which prefetching will occur
* @param {function} options.timeoutFn - Custom timeout function
*/
export default function (options) {
options = Object.assign({
priority: 'low',
timeout: 2e3,
priority: false,
timeoutFn: requestIdleCallback,
el: document,
}, options);
Expand Down
12 changes: 4 additions & 8 deletions src/prefetch.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ const supportedPrefetchStrategy = support(`prefetch`)

/**
* Prefetch a given URL with an optional preferred fetch priority
* @param {string} url - the URL to fetch
* @param {string} priority - preferred fetch priority (`low` or `high`)
* @param {String} url - the URL to fetch
* @param {Boolean} isPriority - if is "high" priority
* @return {Object} a Promise
*/
async function prefetcher(url, priority) {
async function prefetcher(url, isPriority) {
if (preFetched[url]) {
return;
}
Expand All @@ -134,11 +134,7 @@ async function prefetcher(url, priority) {
}

try {
if (priority && priority === `high`) {
await highPriFetchStrategy(url);
} else {
await supportedPrefetchStrategy(url);
};
await (isPriority ? highPriFetchStrategy : supportedPrefetchStrategy)(url);
preFetched[url] = true;
} catch (e) {
// Wanna do something?
Expand Down

0 comments on commit e478a47

Please sign in to comment.