Created
April 2, 2015 15:37
-
-
Save pukhalski/485da0816c5165023ada to your computer and use it in GitHub Desktop.
This file contains hidden or 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
define(['jquery', 'underscore'], function ($, _) { | |
var _hashes = [], | |
hashify; | |
hashify = function (params) { | |
return JSON.stringify(params); | |
}; | |
return function (url, options) { | |
var hash, | |
xhr; | |
// If url is an object, simulate pre-1.5 signature | |
if ( typeof url === "object" ) { | |
options = url; | |
url = options['url']; | |
} | |
// Force options to be an object | |
options = options || {}; | |
options['method'] = options['method'] || 'GET'; | |
options['data'] = options['data'] || {}; | |
options['url'] = url; | |
hash = hashify(options); | |
xhr = $.ajax(url, options).always(function () { | |
_hashes = _.without(_hashes, hashify(options)); | |
console.log(_hashes); | |
}); | |
if (_.contains(_hashes, hash)) { | |
return xhr.abort(); | |
}else{ | |
_hashes.push(hash); | |
return xhr; | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment