From 7571d4c02aea42d6906a7e64e7ed8966f2ae892b Mon Sep 17 00:00:00 2001 From: cpojer Date: Wed, 10 Aug 2011 17:34:52 -0700 Subject: [PATCH] Remove usage of JX.defer in favor of setTimeout Summary: - Test Plan: This was a pretty straightforward replace. Everything should be sane. Reviewed By: epriestley Reviewers: tomo, epriestley, mroch CC: aran, epriestley Differential Revision: 803 --- webroot/rsrc/js/application/core/ShapedRequest.js | 15 ++++++++------- .../js/application/core/behavior-drag-and-drop.js | 2 +- .../application/core/behavior-object-selector.js | 6 ++---- .../js/application/core/behavior-watch-anchor.js | 13 ++++++------- webroot/rsrc/js/application/countdown/timer.js | 2 +- .../js/application/diffusion/behavior-jump-to.js | 8 +++----- .../rsrc/js/application/herald/PathTypeahead.js | 3 +-- 7 files changed, 22 insertions(+), 27 deletions(-) diff --git a/webroot/rsrc/js/application/core/ShapedRequest.js b/webroot/rsrc/js/application/core/ShapedRequest.js index dd03b30def..0f0e0d68d1 100644 --- a/webroot/rsrc/js/application/core/ShapedRequest.js +++ b/webroot/rsrc/js/application/core/ShapedRequest.js @@ -42,8 +42,7 @@ JX.install('PhabricatorShapedRequest', { return; } - this._defer && this._defer.stop(); - + clearTimeout(this._defer); var data = this._dataCallback(); if (this.shouldSendRequest(this._last, data)) { @@ -52,10 +51,11 @@ JX.install('PhabricatorShapedRequest', { this._callback(r); this._min = new Date().getTime() + this.getRateLimit(); - this._defer && this._defer.stop(); - this._defer = JX.defer( + clearTimeout(this._defer); + this._defer = setTimeout( JX.bind(this, this.trigger), - this.getRateLimit()); + this.getRateLimit() + ); })); request.listen('finally', JX.bind(this, function() { this._request = null; @@ -64,9 +64,10 @@ JX.install('PhabricatorShapedRequest', { request.setTimeout(this.getRequestTimeout()); request.send(); } else { - this._defer = JX.defer( + this._defer = setTimeout( JX.bind(this, this.trigger), - this.getFrequency()); + this.getFrequency() + ); } }, diff --git a/webroot/rsrc/js/application/core/behavior-drag-and-drop.js b/webroot/rsrc/js/application/core/behavior-drag-and-drop.js index 623fa92cbc..280a62292a 100644 --- a/webroot/rsrc/js/application/core/behavior-drag-and-drop.js +++ b/webroot/rsrc/js/application/core/behavior-drag-and-drop.js @@ -39,7 +39,7 @@ JX.behavior('aphront-drag-and-drop', function(config) { redraw(true); // This redraws the instructions. - JX.defer(redraw, 1000); + setTimeout(redraw, 1000); }); drop.start(); diff --git a/webroot/rsrc/js/application/core/behavior-object-selector.js b/webroot/rsrc/js/application/core/behavior-object-selector.js index 034fa579b1..9864a329e5 100644 --- a/webroot/rsrc/js/application/core/behavior-object-selector.js +++ b/webroot/rsrc/js/application/core/behavior-object-selector.js @@ -173,10 +173,8 @@ JX.behavior('phabricator-object-selector', function(config) { } last_value = cur_value; - if (query_timer) { - query_timer.stop(); - } - query_timer = JX.defer(sendQuery, query_delay); + clearTimeout(query_timer); + query_timer = setTimeout(sendQuery, query_delay); }); sendQuery(); diff --git a/webroot/rsrc/js/application/core/behavior-watch-anchor.js b/webroot/rsrc/js/application/core/behavior-watch-anchor.js index 0fc429b04a..8d8c0e5ca1 100644 --- a/webroot/rsrc/js/application/core/behavior-watch-anchor.js +++ b/webroot/rsrc/js/application/core/behavior-watch-anchor.js @@ -24,11 +24,10 @@ JX.behavior('phabricator-watch-anchor', function() { } } - JX.Stratcom.listen( - 'hashchange', - null, - // Defer invocation so other listeners can update the document. - function() { JX.defer(highlight); }); - - JX.defer(highlight); + // Defer invocation so other listeners can update the document. + var fn = function() { + setTimeout(highlight, 0); + }; + JX.Stratcom.listen('hashchange', null, fn); + fn(); }); diff --git a/webroot/rsrc/js/application/countdown/timer.js b/webroot/rsrc/js/application/countdown/timer.js index ef944e6cd0..c7de7b7582 100644 --- a/webroot/rsrc/js/application/countdown/timer.js +++ b/webroot/rsrc/js/application/countdown/timer.js @@ -42,7 +42,7 @@ JX.behavior('countdown-timer', function(config) { JX.DOM.setContent(JX.$('phabricator-timer-minutes'), minutes); JX.DOM.setContent(JX.$('phabricator-timer-seconds'), seconds); - JX.defer(calculateTimeLeft, 1000); + setTimeout(calculateTimeLeft, 1000); } }); diff --git a/webroot/rsrc/js/application/diffusion/behavior-jump-to.js b/webroot/rsrc/js/application/diffusion/behavior-jump-to.js index 46604a4d66..6c51dc814a 100644 --- a/webroot/rsrc/js/application/diffusion/behavior-jump-to.js +++ b/webroot/rsrc/js/application/diffusion/behavior-jump-to.js @@ -8,10 +8,8 @@ JX.behavior('diffusion-jump-to', function(config) { - JX.defer( - function() { - window.scrollTo(0, JX.$V(JX.$(config.target)).y - 100); - }); + setTimeout(function() { + window.scrollTo(0, JX.$V(JX.$(config.target)).y - 100); + }, 0); }); - diff --git a/webroot/rsrc/js/application/herald/PathTypeahead.js b/webroot/rsrc/js/application/herald/PathTypeahead.js index 7ef3a9b094..988d728ced 100644 --- a/webroot/rsrc/js/application/herald/PathTypeahead.js +++ b/webroot/rsrc/js/application/herald/PathTypeahead.js @@ -98,8 +98,7 @@ JX.install('PathTypeahead', { this._typeahead.listen( 'choose', JX.bind(this, function() { - JX.defer( - JX.bind(this._typeahead, this._typeahead.refresh)); + setTimeout(JX.bind(this._typeahead, this._typeahead.refresh), 0); })); var repo_set_input = JX.bind(this, this._onrepochange);