Permalink
Browse files

Core: Switch from modules to just window.setTimeout etc.

Using modules for window.setTimeout etc. made those functions cached and
disabled Sinon mocking, making effects tests fail. Just writing
window.setTimeout directly is smaller anyway.
  • Loading branch information...
mgol committed Jun 17, 2015
1 parent 219c749 commit 842958e7aecd0d75a7ee9e2aaec83457701aa2f3
Showing with 14 additions and 37 deletions.
  1. +3 −6 src/ajax.js
  2. +2 −3 src/core/ready.js
  3. +2 −3 src/deferred.js
  4. +4 −8 src/effects.js
  5. +3 −5 src/queue/delay.js
  6. +0 −3 src/var/clearInterval.js
  7. +0 −3 src/var/clearTimeout.js
  8. +0 −3 src/var/setInterval.js
  9. +0 −3 src/var/setTimeout.js
View
@@ -2,17 +2,14 @@ define([
"./core",
"./var/document",
"./var/rnotwhite",
"./var/setTimeout",
"./var/clearTimeout",
"./ajax/var/location",
"./ajax/var/nonce",
"./ajax/var/rquery",
"./core/init",
"./ajax/parseJSON",
"./ajax/parseXML",
"./deferred"
], function( jQuery, document, rnotwhite, setTimeout, clearTimeout,
location, nonce, rquery ) {
], function( jQuery, document, rnotwhite, location, nonce, rquery ) {
var
rhash = /#.*$/,
@@ -645,7 +642,7 @@ jQuery.extend({
// Timeout
if ( s.async && s.timeout > 0 ) {
timeoutTimer = setTimeout(function() {
timeoutTimer = window.setTimeout(function() {
jqXHR.abort("timeout");
}, s.timeout );
}
@@ -679,7 +676,7 @@ jQuery.extend({
// Clear timeout if it exists
if ( timeoutTimer ) {
clearTimeout( timeoutTimer );
window.clearTimeout( timeoutTimer );
}
// Dereference transport for early garbage collection
View
@@ -1,9 +1,8 @@
define([
"../core",
"../var/document",
"../var/setTimeout",
"../deferred"
], function( jQuery, document, setTimeout ) {
], function( jQuery, document ) {
// The deferred used on DOM ready
var readyList;
@@ -74,7 +73,7 @@ jQuery.ready.promise = function( obj ) {
// discovered by ChrisS here: http://bugs.jquery.com/ticket/12282#comment:15
if ( document.readyState === "complete" ) {
// Handle it asynchronously to allow scripts the opportunity to delay ready
setTimeout( jQuery.ready );
window.setTimeout( jQuery.ready );
} else {
View
@@ -1,9 +1,8 @@
define([
"./core",
"./var/slice",
"./var/setTimeout",
"./callbacks"
], function( jQuery, slice, setTimeout ) {
], function( jQuery, slice ) {
function Identity( v ) {
return v;
@@ -174,7 +173,7 @@ jQuery.extend({
if ( depth ) {
process();
} else {
setTimeout( process );
window.setTimeout( process );
}
};
}
View
@@ -2,9 +2,6 @@ define([
"./core",
"./var/document",
"./var/rcssNum",
"./var/setInterval",
"./var/clearInterval",
"./var/setTimeout",
"./css/var/cssExpand",
"./css/var/isHidden",
"./css/var/swap",
@@ -19,8 +16,7 @@ define([
"./manipulation",
"./css",
"./effects/Tween"
], function( jQuery, document, rcssNum, setInterval, clearInterval, setTimeout,
cssExpand, isHidden, swap, adjustCSS, dataPriv, showHide ) {
], function( jQuery, document, rcssNum, cssExpand, isHidden, swap, adjustCSS, dataPriv, showHide ) {
var
fxNow, timerId,
@@ -44,7 +40,7 @@ function raf() {
// Animations created synchronously will run synchronously
function createFxNow() {
setTimeout(function() {
window.setTimeout(function() {
fxNow = undefined;
});
return ( fxNow = jQuery.now() );
@@ -638,15 +634,15 @@ jQuery.fx.start = function() {
if ( !timerId ) {
timerId = window.requestAnimationFrame ?
window.requestAnimationFrame( raf ) :
setInterval( jQuery.fx.tick, jQuery.fx.interval );
window.setInterval( jQuery.fx.tick, jQuery.fx.interval );
}
};
jQuery.fx.stop = function() {
if ( window.cancelAnimationFrame ) {
window.cancelAnimationFrame( timerId );
} else {
clearInterval( timerId );
window.clearInterval( timerId );
}
timerId = null;
View
@@ -1,10 +1,8 @@
define([
"../core",
"../var/setTimeout",
"../var/clearTimeout",
"../queue",
"../effects" // Delay is optional because of this dependency
], function( jQuery, setTimeout, clearTimeout ) {
], function( jQuery ) {
// Based off of the plugin by Clint Helfers, with permission.
// http://web.archive.org/web/20100324014747/http://blindsignals.com/index.php/2009/07/jquery-delay/
@@ -13,9 +11,9 @@ jQuery.fn.delay = function( time, type ) {
type = type || "fx";
return this.queue( type, function( next, hooks ) {
var timeout = setTimeout( next, time );
var timeout = window.setTimeout( next, time );
hooks.stop = function() {
clearTimeout( timeout );
window.clearTimeout( timeout );
};
});
};
View
@@ -1,3 +0,0 @@
define(function() {
return window.clearInterval;
});
View
@@ -1,3 +0,0 @@
define(function() {
return window.clearTimeout;
});
View
@@ -1,3 +0,0 @@
define(function() {
return window.setInterval;
});
View
@@ -1,3 +0,0 @@
define(function() {
return window.setTimeout;
});

4 comments on commit 842958e

@markelog

This comment has been minimized.

Show comment
Hide comment
@markelog

markelog Jun 17, 2015

Member

Told ya :-)

Member

markelog replied Jun 17, 2015

Told ya :-)

@mgol

This comment has been minimized.

Show comment
Hide comment
@mgol

mgol Jun 17, 2015

Member

Sinon made me do it. :P

Member

mgol replied Jun 17, 2015

Sinon made me do it. :P

@dmethvin

This comment has been minimized.

Show comment
Hide comment
@dmethvin

dmethvin Jun 17, 2015

Member

Funny thing is, doing the opposite and letting Sinon get its hands on stuff can break code too. petkaantonov/bluebird#631

Member

dmethvin replied Jun 17, 2015

Funny thing is, doing the opposite and letting Sinon get its hands on stuff can break code too. petkaantonov/bluebird#631

Please sign in to comment.