angular-debounce
Advanced tools
Comparing version 1.0.3 to 1.1.0
{ | ||
"name": "angular-debounce", | ||
"version": "1.0.3", | ||
"version": "1.1.0", | ||
"main": "dist/angular-debounce.js", | ||
@@ -5,0 +5,0 @@ "ignore": [ |
angular.module('rt.debounce', []).factory('debounce', [ | ||
'$timeout', | ||
function ($timeout) { | ||
return function (wait, fn) { | ||
return function (wait, fn, no_postpone) { | ||
var args, context, result, timeout; | ||
var executed = true; | ||
// Execute the callback function | ||
@@ -10,2 +11,3 @@ function ping() { | ||
context = args = null; | ||
executed = true; | ||
} | ||
@@ -25,4 +27,9 @@ // Cancel the timeout (for rescheduling afterwards). | ||
args = arguments; | ||
cancel(); | ||
timeout = $timeout(ping, wait); | ||
if (!no_postpone) { | ||
cancel(); | ||
timeout = $timeout(ping, wait); | ||
} else if (executed) { | ||
executed = false; | ||
timeout = $timeout(ping, wait); | ||
} | ||
} | ||
@@ -29,0 +36,0 @@ // Forces the execution of pending calls |
@@ -1,1 +0,1 @@ | ||
angular.module("rt.debounce",[]).factory("debounce",["$timeout",function(a){return function(b,c){function d(){j=c.apply(i||this,h||[]),i=h=null}function e(){k&&(a.cancel(k),k=null)}function f(){i=this,h=arguments,e(),k=a(d,b)}function g(){var a=!!i;return a&&(e(),d()),a}var h,i,j,k;return f.flush=function(){return g()||k||d(),j},f.flushPending=function(){return g(),j},f.cancel=e,f}}]); | ||
angular.module("rt.debounce",[]).factory("debounce",["$timeout",function(a){return function(b,c,d){function e(){k=c.apply(j||this,i||[]),j=i=null,m=!0}function f(){l&&(a.cancel(l),l=null)}function g(){j=this,i=arguments,d?m&&(m=!1,l=a(e,b)):(f(),l=a(e,b))}function h(){var a=!!j;return a&&(f(),e()),a}var i,j,k,l,m=!0;return g.flush=function(){return h()||l||e(),k},g.flushPending=function(){return h(),k},g.cancel=f,g}}]); |
{ | ||
"name": "angular-debounce", | ||
"version": "1.0.3", | ||
"version": "1.1.0", | ||
"description": "Tiny debouncing function for Angular.JS.", | ||
@@ -25,17 +25,19 @@ "main": "dist/angular-debounce.js", | ||
"chai": "~1.9.0", | ||
"grunt": "~0.4.4", | ||
"grunt-bump": "0.0.13", | ||
"grunt-contrib-clean": "~0.5.0", | ||
"grunt-contrib-concat": "~0.3.0", | ||
"grunt-contrib-jshint": "~0.9.2", | ||
"grunt-contrib-uglify": "~0.4.0", | ||
"grunt-contrib-watch": "~0.6.0", | ||
"grunt-karma": "~0.8.0", | ||
"grunt": "^1.0.0", | ||
"grunt-bump": "~0.8.0", | ||
"grunt-contrib-clean": "^1.0.0", | ||
"grunt-contrib-concat": "^1.0.0", | ||
"grunt-contrib-jshint": "^1.0.0", | ||
"grunt-contrib-uglify": "^1.0.0", | ||
"grunt-contrib-watch": "^1.0.0", | ||
"grunt-karma": "^1.0.0", | ||
"grunt-ngmin": "0.0.3", | ||
"karma": "^0.13.22", | ||
"karma-chai": "~0.1.0", | ||
"karma-chrome-launcher": "~0.1.2", | ||
"karma-firefox-launcher": "~0.1.3", | ||
"karma-mocha": "~0.1.1", | ||
"karma-phantomjs-launcher": "~0.1.2", | ||
"mocha": "~1.17.1" | ||
"karma-chrome-launcher": "^1.0.0", | ||
"karma-firefox-launcher": "^1.0.0", | ||
"karma-mocha": "^1.0.0", | ||
"karma-phantomjs-launcher": "^1.0.0", | ||
"mocha": "~2.4.5", | ||
"phantomjs-prebuilt": "^2.1.7" | ||
}, | ||
@@ -42,0 +44,0 @@ "repository": { |
@@ -51,3 +51,4 @@ # angular-debounce | ||
// Want to stop waiting and send out the call immedialtely if any was made? Flush pending calls! | ||
// Want to stop waiting and send out the call immediately if any was made? | ||
// Flush pending calls! | ||
fn.flushPending(); | ||
@@ -60,2 +61,10 @@ | ||
Repeatedly calling `fn()` will postpone indefinitely. Pass a third `true` parameter to also fire intermediate calls: | ||
```js | ||
var fn = debounce(2000, function () { | ||
// Do things here. | ||
}, true); | ||
``` | ||
## License | ||
@@ -62,0 +71,0 @@ |
11234
171
91
18