-
Notifications
You must be signed in to change notification settings - Fork 2
/
backbone-ajaxretry.min.js
6 lines (6 loc) · 1.3 KB
/
backbone-ajaxretry.min.js
1
2
3
4
5
6
/*!
* Backbone.js ajaxRetry
* https://github.com/gdibble/backbone-ajaxretry
* Copyright 2015 Gabriel Dibble; Licensed MIT
*/
var defaults=require("lodash.defaults"),extend=require("extend-object");!function(e){e(function(e,t,r){function n(e){defaults(e,f),f=e}function s(e){return 1e3*(Math.pow(f.base,e)-f.y)}function a(){var e=Array.prototype.slice.call(arguments,0);extend(e[0],this),this.hasOwnProperty("exhaust")&&this.exhaust.apply(this,e)}function u(e){var t=this;this.hasOwnProperty("retries")?(this.recursed=void 0===this.recursed?0:this.recursed+1,e&&e.status<500||this.recursed>=this.retries?a.apply(t,arguments):this.recursed<this.retries&&setTimeout(function(){$.ajax(t)},s(this.recursed))):a.apply(t,arguments)}function i(e,t){extend(e[0],t&&"object"==typeof t?t:{},{retries:f.retryCount,error:function(){u.apply(this,arguments)}})}function o(){return Array.prototype.slice.call(arguments,0)}var c,p=e("backbone"),f={base:2.718281828,y:.25,retryCount:3,onlyBackbone:!1};f.onlyBackbone?p.ajax=function(e){var t=o(arguments);return i(t,e),p.$.ajax.apply(p.$,t)}:(c=$.ajax,$.ajax=function(e){var t;return"string"==typeof e?(arguments[1].url=e,t=o(arguments[1]),i(t,e)):(t=o(arguments),i(t,e)),c.apply($,t)}),r.exports={set:n}})}("function"==typeof define&&define.amd?define:function(e){e(require,exports,module)});