Created
February 25, 2011 21:58
-
-
Save lsmith/844579 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/jsonp/js/jsonp.js b/src/jsonp/js/jsonp.js | |
index f6f6b44..91d2634 100644 | |
--- a/src/jsonp/js/jsonp.js | |
+++ b/src/jsonp/js/jsonp.js | |
@@ -122,6 +122,9 @@ JSONPRequest.prototype = { | |
// In case additional requests are issued before the current reques | |
// returns, don't remove the proxy. | |
self._requests++; | |
+ if (!('_timeouts' in self)) { | |
+ self._timeouts = 0; | |
+ } | |
} | |
args.unshift(self.url, 'YUI.Env.JSONP.' + proxy); | |
@@ -132,13 +135,35 @@ JSONPRequest.prototype = { | |
return self; | |
} | |
- function wrap(fn) { | |
+ function wrap(fn, isTimeout) { | |
return (isFunction(fn)) ? | |
function (data) { | |
- if (!config.allowCache || !--self._requests) { | |
+ var execute = true, | |
+ counter = '_requests'; | |
+ | |
+ if (config.allowCache) { | |
+ // A lot of wrangling to make sure timeouts result in | |
+ // fewer success callbacks, but the proxy is properly | |
+ // cleaned up. | |
+ if (isTimeout) { | |
+ ++self._timeouts; | |
+ --self._requests; | |
+ } else { | |
+ if (!self._requests) { | |
+ execute = false; | |
+ counter = '_timeouts'; | |
+ } | |
+ --self[counter]; | |
+ } | |
+ } | |
+ | |
+ if (!config.allowCache || !self[counter]) { | |
delete YUI.Env.JSONP[proxy]; | |
} | |
- fn.apply(config.context, [data].concat(config.args)); | |
+ | |
+ if (execute) { | |
+ fn.apply(config.context, [data].concat(config.args)); | |
+ } | |
} : | |
null; | |
} | |
@@ -149,7 +174,7 @@ JSONPRequest.prototype = { | |
Y.Get.script(url, { | |
onFailure: wrap(config.on.failure), | |
- onTimeout: wrap(config.on.timeout), | |
+ onTimeout: wrap(config.on.timeout, true), | |
timeout : config.timeout | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment