-
Notifications
You must be signed in to change notification settings - Fork 27.4k
feat($timeout): Add debouncing support #4500
Conversation
Thanks for the PR!
If you need to make changes to your pull request, you can update the commit with Thanks again for your help! |
I've already signed the CLA. The commit message seems to be ok too, just tell me if I need to change anything. |
* } | ||
* $scope.save = function() { | ||
* // debounce call for 2 seconds | ||
* debounce = $timeout(doRealSave, 2000, debounce); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems the signature is incorrect as the function timeout
definition has the debounce
argument in the 4th position.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! Fixed. Thanks!
By the way, I forgot to tell that the PR is rebased to a recent master. |
@petebacondarwin, |
Ok. Thanks again! |
Rebased to latest master (which is the official 1.2.0) and solved a rebase conflict. By the way, the Travis CI build failed due to #4822 |
@lrlopez - thanks for hanging in there on these PRs. No that 1.2.0 is out we can start going through these. |
@petebacondarwin, |
This feature allows resetting the timer on an ongoing `$timeout` promise. A fourth optional argument is added to `$timeout` which is the old promise to be reset. I.e.: `promise = $timeout(fn, 2000, true, promise);` This will call `fn()` 2 seconds after the last call to the `$timeout()` function.
It may be a good time to assign this PR a more concrete milestone... |
Closed as #2945 has landed |
This feature allows resetting the timer on an ongoing
$timeout
promise. The implementation is really simple (see the diff) and fully backwards compatible. Documentation and tests are included. It adds just 98 bytes to the current minified build.The PR adds a fourth optional argument to
$timeout
which is the old promise to be reset.With this feature you can debounce events. In the following example,
doRealSave()
will only be called 2 seconds after the last model change:And in the form:
This PR has been extracted from a bigger one: #2129