@@ -72,25 +72,23 @@ function isIgnored(node, filter) {
72
72
* @param {Function } options.timeoutFn - Custom timeout function
73
73
*/
74
74
export default function ( options ) {
75
- options = Object . assign ( {
76
- timeout : 2e3 ,
77
- priority : false ,
78
- timeoutFn : requestIdleCallback ,
79
- el : document ,
80
- } , options ) ;
75
+ if ( ! options ) options = { } ;
81
76
82
- observer . priority = options . priority ;
77
+ observer . priority = options . priority || false ;
83
78
84
79
const allowed = options . origins || [ location . hostname ] ;
85
80
const ignores = options . ignores || [ ] ;
86
81
87
- options . timeoutFn ( ( ) => {
82
+ const timeout = options . timeout || 2e3 ;
83
+ const timeoutFn = options . timeoutFn || requestIdleCallback ;
84
+
85
+ timeoutFn ( ( ) => {
88
86
// If URLs are given, prefetch them.
89
87
if ( options . urls ) {
90
88
options . urls . forEach ( prefetcher ) ;
91
89
} else {
92
90
// If not, find all links and use IntersectionObserver.
93
- Array . from ( options . el . querySelectorAll ( 'a' ) , link => {
91
+ Array . from ( ( options . el || document ) . querySelectorAll ( 'a' ) , link => {
94
92
observer . observe ( link ) ;
95
93
// If the anchor matches a permitted origin
96
94
// ~> A `[]` or `true` means everything is allowed
@@ -100,5 +98,5 @@ export default function (options) {
100
98
}
101
99
} ) ;
102
100
}
103
- } , { timeout : options . timeout } ) ;
101
+ } , { timeout} ) ;
104
102
}
0 commit comments