Skip to content

Commit

Permalink
Fixing throttling in Delegator.Ajax
Browse files Browse the repository at this point in the history
  • Loading branch information
anutron committed Oct 25, 2013
1 parent 4c6f246 commit d611d6e
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions Source/Delegators/Delegator.Ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ name: Delegator.Ajax
var spinnerTarget = api.get('spinnerTarget') || api.get('spinner-target'); //spinner-target is deprecated
if (spinnerTarget) spinnerTarget = link.getElement(spinnerTarget);

event.preventDefault();

var request = new Request.HTML(
Object.cleanValues({
method: api.get('method'),
Expand Down Expand Up @@ -102,14 +100,15 @@ name: Delegator.Ajax
throttle: 0 //prevents sending repeatedly within this threshold
},
handler: function(event, link, api){
event.preventDefault();
// if the throttle is set and != 0
if (api.get('throttle')){
// store the timer on the element for subsequent requests
var timer = link.retrieve('ajaxTimer');
// clear the previous running timer if there is one
if (timer) clearTimeout(timer);
// store the new one; delaying the send call by the configured amount
link.store('ajaxTimer', send.delay(api.get('throttle'), this, arguments));
link.store('ajaxTimer', send.delay(api.getAs(Number, 'throttle'), this, arguments));
} else {
// otherwise hey, no throttle. send it.
send.apply(this, arguments);
Expand Down

0 comments on commit d611d6e

Please sign in to comment.