mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-17 07:40:22 +00:00
Added delay parameter to the $defer service
This commit is contained in:
parent
9e67da420b
commit
edbe9d8ca8
4 changed files with 13 additions and 3 deletions
|
|
@ -5,6 +5,8 @@
|
|||
- rewrite of JQuery lite implementation for better supports operations on multiple nodes when
|
||||
matched by a selector.
|
||||
- Infer DI dependencies from function signature. http://docs.angularjs.org/#!guide.di
|
||||
- Added delay parameter to the $defer service
|
||||
|
||||
|
||||
### Breaking changes
|
||||
- Removed the $init() method after the compilation. The old way of compiling the DOM element was
|
||||
|
|
|
|||
|
|
@ -324,7 +324,7 @@ function Browser(window, document, body, XHR, $log) {
|
|||
* @name angular.service.$browser#defer
|
||||
* @methodOf angular.service.$browser
|
||||
* @param {function()} fn A function, who's execution should be defered.
|
||||
* @param {int=} [delay=0] of milliseconds to defer the function execution.
|
||||
* @param {number=} [delay=0] of milliseconds to defer the function execution.
|
||||
*
|
||||
* @description
|
||||
* Executes a fn asynchroniously via `setTimeout(fn, delay)`.
|
||||
|
|
|
|||
|
|
@ -14,9 +14,10 @@
|
|||
* In tests you can use `$browser.defer.flush()` to flush the queue of deferred functions.
|
||||
*
|
||||
* @param {function()} fn A function, who's execution should be deferred.
|
||||
* @param {number=} [delay=0] of milliseconds to defer the function execution.
|
||||
*/
|
||||
angularServiceInject('$defer', function($browser, $exceptionHandler, $updateView) {
|
||||
return function(fn) {
|
||||
return function(fn, delay) {
|
||||
$browser.defer(function() {
|
||||
try {
|
||||
fn();
|
||||
|
|
@ -25,6 +26,6 @@ angularServiceInject('$defer', function($browser, $exceptionHandler, $updateView
|
|||
} finally {
|
||||
$updateView();
|
||||
}
|
||||
});
|
||||
}, delay);
|
||||
};
|
||||
}, ['$browser', '$exceptionHandler', '$updateView']);
|
||||
|
|
|
|||
|
|
@ -66,4 +66,11 @@ describe('$defer', function() {
|
|||
$browser.defer.flush();
|
||||
expect(eval).wasCalled();
|
||||
});
|
||||
|
||||
it('should allow you to specify the delay time', function(){
|
||||
var defer = this.spyOn($browser, 'defer');
|
||||
$defer(noop, 123);
|
||||
expect(defer.callCount).toEqual(1);
|
||||
expect(defer.mostRecentCall.args[1]).toEqual(123);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue