Explorar el Código

use native timeout for fallback and resolve the promise asap

Gildas hace 7 años
padre
commit
c58a4ae124
Se han modificado 1 ficheros con 5 adiciones y 5 borrados
  1. 5 5
      lib/lazy/content-lazy-loader.js

+ 5 - 5
lib/lazy/content-lazy-loader.js

@@ -18,7 +18,7 @@
  *   along with SingleFile.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-/* global browser, document, timeout, MutationObserver */
+/* global browser, document, timeout, MutationObserver, setTimeout, clearTimeout */
 
 this.lazyLoader = this.lazyLoader || (() => {
 
@@ -39,10 +39,10 @@ this.lazyLoader = this.lazyLoader || (() => {
 					lazyLoadEnd(maxTimeoutId, idleTimeoutId, observer, options, resolve);
 				}
 			}, options.maxLazyLoadImagesIdleTime * 1.2);
-			const maxTimeoutId = timeout.set(() => {
+			const maxTimeoutId = setTimeout(() => {
 				timeout.clear(timeoutId);
 				lazyLoadEnd(maxTimeoutId, idleTimeoutId, observer, options, resolve);
-			}, options.maxLazyLoadImagesIdleTime * 10);
+			}, options.maxLazyLoadImagesIdleTime * 3);
 			const observer = new MutationObserver(mutations => {
 				mutations = mutations.filter(mutation => mutation.type == ATTRIBUTES_MUTATION_TYPE);
 				if (mutations.length) {
@@ -66,9 +66,9 @@ this.lazyLoader = this.lazyLoader || (() => {
 	}
 
 	function lazyLoadEnd(maxTimeoutId, idleTimeoutId, observer, options, resolve) {
-		timeout.clear(maxTimeoutId);
+		clearTimeout(maxTimeoutId);
 		timeout.clear(idleTimeoutId);
-		timeout.set(resolve, options.maxLazyLoadImagesIdleTime);
+		resolve();
 		injectScript(SCRIPT_AFTER_PATH);
 		observer.disconnect();
 	}