diff --git a/README.md b/README.md index e878508..d4a5fda 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,8 @@ The [annotated source code]() is av ### Downloads (Right-click, and use "Save As") -- [Development Version]() 4.6kb, Uncompressed with Comments -- [Production Version]() 1.8kb, Minified and Gzipped +- [Development Version]() 4.6kb, Uncompressed with Comments +- [Production Version]() 1.8kb, Minified and Gzipped ---- @@ -164,8 +164,13 @@ Backbone.Poller.reset(); ## Change Log +### 1.1.1 +May 31, 2015 - [Diff](https://github.com/uzikilon/backbone-poller/compare/1.0.1...1.1.1) + +- Added a `destroy` method for better garbage collection + ### 1.0.1 -April 18, 2014 - [Diff](https://github.com/uzikilon/backbone-poller/compare/1.0.0...1.0.1) +April 18, 2015 - [Diff](https://github.com/uzikilon/backbone-poller/compare/1.0.0...1.0.1) - Set the delayed parameter to be a number (as well as a boolean) diff --git a/backbone.poller.js b/backbone.poller.js index f9d41af..cf08f99 100644 --- a/backbone.poller.js +++ b/backbone.poller.js @@ -1,6 +1,6 @@ /*! (c) 2012 Uzi Kilon, Splunk Inc. -Backbone Poller 1.0.1 +Backbone Poller 1.1.1 https://github.com/uzikilon/backbone-poller Backbone Poller may be freely distributed under the MIT license. */ diff --git a/backbone.poller.min.js b/backbone.poller.min.js index 9a04e20..7971c87 100644 --- a/backbone.poller.min.js +++ b/backbone.poller.min.js @@ -1,7 +1,7 @@ /*! (c) 2012 Uzi Kilon, Splunk Inc. -Backbone Poller 1.0.1 +Backbone Poller 1.1.1 https://github.com/uzikilon/backbone-poller Backbone Poller may be freely distributed under the MIT license. */ -!function(a,b){"use strict";"function"==typeof define&&define.amd?define(["underscore","backbone"],b):"function"==typeof require&&"object"==typeof exports?module.exports=b(require("underscore"),require("backbone")):a.Backbone.Poller=b(a._,a.Backbone)}(this,function(a,b){"use strict";function c(b){return a.find(k,function(a){return a.model===b})}function d(c,d){this.model=c,this.cid=a.uniqueId("poller"),this.set(d),this.model instanceof b.Model&&this.listenTo(this.model,"destroy",this.destroy)}function e(b){if(h(b)){var c=a.extend({},b.options,{success:function(a,c){b.trigger("success",a,c),g(b)},error:function(a,c){b.options.continueOnError?(b.trigger("error",a,c),g(b)):(b.stop({silent:!0}),b.trigger("error",a,c))}});b.trigger("fetch",b.model),b.xhr=b.model.fetch(c)}}function f(b){if(a.isNumber(b.options.delay))return b.options.delay;var c=b.options.delay[0],d=b.options.delay[1],e=b.options.delay[2]||2;m[b.cid]?a.isFunction(e)?m[b.cid]=e(m[b.cid]):m[b.cid]*=e:m[b.cid]=1;var f=Math.round(c*m[b.cid]);return d&&d>0&&(f=Math.min(f,d)),f}function g(b,c){h(b)&&(b.timeoutId=a.delay(e,c||f(b),b))}function h(a){return a.options.active?a.options.condition(a.model)!==!0?(a.stop({silent:!0}),a.trigger("complete",a.model),!1):!0:!1}var i={delay:1e3,condition:function(){return!0}},j=["start","stop","fetch","success","error","complete"],k=[],l={get:function(a,b){var e=c(a);return e?e.set(b):(e=new d(a,b),k.push(e)),b&&b.autostart===!0&&e.start({silent:!0}),e},size:function(){return k.length},reset:function(){for(;k.length;)k[0].destroy()}};a.extend(d.prototype,b.Events,{set:function(b){return this.options=a.extend({},i,b||{}),this.options.flush&&this.off(),a.each(j,function(b){var c=this.options[b];a.isFunction(c)&&(this.off(b,c,this),this.on(b,c,this))},this),this.stop({silent:!0})},start:function(b){return this.active()||(b&&b.silent||this.trigger("start",this.model),this.options.active=!0,this.options.delayed?g(this,a.isNumber(this.options.delayed)&&this.options.delayed):e(this)),this},stop:function(a){return a&&a.silent||this.trigger("stop",this.model),this.options.active=!1,this.xhr&&this.xhr.abort&&this.xhr.abort(),this.xhr=null,clearTimeout(this.timeoutId),this.timeoutId=null,this},active:function(){return this.options.active===!0},destroy:function(){this.stop(),this.stopListening(),k=a.filter(k,function(a){return a!==this},this)}});var m={};return l.getDelay=f,l.prototype=d.prototype,l}); \ No newline at end of file +!function(a,b){"use strict";"function"==typeof define&&define.amd?define(["underscore","backbone"],b):"function"==typeof require&&"object"==typeof exports?module.exports=b(require("underscore"),require("backbone")):a.Backbone.Poller=b(a._,a.Backbone)}(this,function(a,b){"use strict";function c(b){return a.find(k,function(a){return a.model===b})}function d(c,d){this.model=c,this.cid=a.uniqueId("poller"),this.set(d),this.model instanceof b.Model&&this.listenTo(this.model,"destroy",this.destroy)}function e(b){if(h(b)){var c=a.extend({},b.options,{success:function(a,c){b.trigger("success",a,c),g(b)},error:function(a,c){b.options.continueOnError?(b.trigger("error",a,c),g(b)):(b.stop({silent:!0}),b.trigger("error",a,c))}});b.trigger("fetch",b.model),b.xhr=b.model.fetch(c)}}function f(b){if(a.isNumber(b.options.delay))return b.options.delay;var c=b.options.delay[0],d=b.options.delay[1],e=b.options.delay[2]||2;m[b.cid]?a.isFunction(e)?m[b.cid]=e(m[b.cid]):m[b.cid]*=e:m[b.cid]=1;var f=Math.round(c*m[b.cid]);return d&&d>0&&(f=Math.min(f,d)),f}function g(b,c){h(b)&&(b.timeoutId=a.delay(e,c||f(b),b))}function h(a){return a.options.active?a.options.condition(a.model)!==!0?(a.stop({silent:!0}),a.trigger("complete",a.model),!1):!0:!1}var i={delay:1e3,condition:function(){return!0}},j=["start","stop","fetch","success","error","complete"],k=[],l={get:function(a,b){var e=c(a);return e?e.set(b):(e=new d(a,b),k.push(e)),b&&b.autostart===!0&&e.start({silent:!0}),e},size:function(){return k.length},reset:function(){for(;k.length;)k[0].destroy()}};a.extend(d.prototype,b.Events,{set:function(b){return this.options=a.extend({},i,b||{}),this.options.flush&&this.off(),a.each(j,function(b){var c=this.options[b];a.isFunction(c)&&(this.off(b,c,this),this.on(b,c,this))},this),this.stop({silent:!0})},start:function(b){return this.active()||(b&&b.silent||this.trigger("start",this.model),this.options.active=!0,this.options.delayed?g(this,a.isNumber(this.options.delayed)&&this.options.delayed):e(this)),this},stop:function(a){return a&&a.silent||this.trigger("stop",this.model),this.options.active=!1,this.xhr&&this.xhr.abort&&this.xhr.abort(),this.xhr=null,clearTimeout(this.timeoutId),this.timeoutId=null,this},active:function(){return this.options.active===!0},destroy:function(){this.stop(),this.stopListening(),this.off(),k=a.filter(k,function(a){return a!==this},this)}});var m={};return l.getDelay=f,l.prototype=d.prototype,l}); \ No newline at end of file diff --git a/bower.json b/bower.json index a5b445d..b53f0ba 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "backbone-poller", - "version": "1.0.1", + "version": "1.1.1", "homepage": "https://github.com/uzikilon/backbone-poller", "description": "Backbone poller is a simple utility that allows polling on any backbone model or collection.", "main": "backbone.poller.js", diff --git a/package.json b/package.json index 8f83864..e3f3121 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "author": "Uzi Kilon", "name": "backbone-poller", - "version": "1.0.1", + "version": "1.1.1", "homepage": "https://github.com/uzikilon/backbone-poller", "repository": { "type": "git",