X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=resources%2Fsrc%2Fstartup%2Fmediawiki.requestIdleCallback.js;h=2787f585d4c138f3278fde1b538d25d9f9047405;hp=afb4737631d3f78414c162ebe76d86e3f3293058;hb=7512d9a4a132ec2c3a1178102008087866a9c36d;hpb=b53f299af26aa0b14b3cd3cc37ec1126a61cdc62 diff --git a/resources/src/startup/mediawiki.requestIdleCallback.js b/resources/src/startup/mediawiki.requestIdleCallback.js index afb4737631..2787f585d4 100644 --- a/resources/src/startup/mediawiki.requestIdleCallback.js +++ b/resources/src/startup/mediawiki.requestIdleCallback.js @@ -1,54 +1,51 @@ /* global mw */ -( function () { - var maxBusy = 50; +mw.requestIdleCallbackInternal = function ( callback ) { + setTimeout( function () { + var start = mw.now(); + callback( { + didTimeout: false, + timeRemaining: function () { + // Hard a target maximum busy time of 50 milliseconds + return Math.max( 0, 50 - ( mw.now() - start ) ); + } + } ); + }, 1 ); +}; - mw.requestIdleCallbackInternal = function ( callback ) { - setTimeout( function () { - var start = mw.now(); - callback( { - didTimeout: false, - timeRemaining: function () { - return Math.max( 0, maxBusy - ( mw.now() - start ) ); - } - } ); - }, 1 ); - }; - - /** - * Schedule a deferred task to run in the background. - * - * This allows code to perform tasks in the main thread without impacting - * time-critical operations such as animations and response to input events. - * - * Basic logic is as follows: - * - * - User input event should be acknowledged within 100ms per [RAIL]. - * - Idle work should be grouped in blocks of upto 50ms so that enough time - * remains for the event handler to execute and any rendering to take place. - * - Whenever a native event happens (e.g. user input), the deadline for any - * running idle callback drops to 0. - * - As long as the deadline is non-zero, other callbacks pending may be - * executed in the same idle period. - * - * See also: - * - * - - * - - * - - * [RAIL]: https://developers.google.com/web/fundamentals/performance/rail - * - * @member mw - * @param {Function} callback - * @param {Object} [options] - * @param {number} [options.timeout] If set, the callback will be scheduled for - * immediate execution after this amount of time (in milliseconds) if it didn't run - * by that time. - */ - mw.requestIdleCallback = window.requestIdleCallback ? - // Bind because it throws TypeError if context is not window - window.requestIdleCallback.bind( window ) : - mw.requestIdleCallbackInternal; - // Note: Polyfill was previously disabled due to - // https://bugs.chromium.org/p/chromium/issues/detail?id=647870 - // See also -}() ); +/** + * Schedule a deferred task to run in the background. + * + * This allows code to perform tasks in the main thread without impacting + * time-critical operations such as animations and response to input events. + * + * Basic logic is as follows: + * + * - User input event should be acknowledged within 100ms per [RAIL]. + * - Idle work should be grouped in blocks of upto 50ms so that enough time + * remains for the event handler to execute and any rendering to take place. + * - Whenever a native event happens (e.g. user input), the deadline for any + * running idle callback drops to 0. + * - As long as the deadline is non-zero, other callbacks pending may be + * executed in the same idle period. + * + * See also: + * + * - + * - + * - + * [RAIL]: https://developers.google.com/web/fundamentals/performance/rail + * + * @member mw + * @param {Function} callback + * @param {Object} [options] + * @param {number} [options.timeout] If set, the callback will be scheduled for + * immediate execution after this amount of time (in milliseconds) if it didn't run + * by that time. + */ +mw.requestIdleCallback = window.requestIdleCallback ? + // Bind because it throws TypeError if context is not window + window.requestIdleCallback.bind( window ) : + mw.requestIdleCallbackInternal; +// Note: Polyfill was previously disabled due to +// https://bugs.chromium.org/p/chromium/issues/detail?id=647870 +// See also