mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-19 08:00:23 +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
|
- rewrite of JQuery lite implementation for better supports operations on multiple nodes when
|
||||||
matched by a selector.
|
matched by a selector.
|
||||||
- Infer DI dependencies from function signature. http://docs.angularjs.org/#!guide.di
|
- Infer DI dependencies from function signature. http://docs.angularjs.org/#!guide.di
|
||||||
|
- Added delay parameter to the $defer service
|
||||||
|
|
||||||
|
|
||||||
### Breaking changes
|
### Breaking changes
|
||||||
- Removed the $init() method after the compilation. The old way of compiling the DOM element was
|
- 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
|
* @name angular.service.$browser#defer
|
||||||
* @methodOf angular.service.$browser
|
* @methodOf angular.service.$browser
|
||||||
* @param {function()} fn A function, who's execution should be defered.
|
* @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
|
* @description
|
||||||
* Executes a fn asynchroniously via `setTimeout(fn, delay)`.
|
* 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.
|
* 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 {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) {
|
angularServiceInject('$defer', function($browser, $exceptionHandler, $updateView) {
|
||||||
return function(fn) {
|
return function(fn, delay) {
|
||||||
$browser.defer(function() {
|
$browser.defer(function() {
|
||||||
try {
|
try {
|
||||||
fn();
|
fn();
|
||||||
|
|
@ -25,6 +26,6 @@ angularServiceInject('$defer', function($browser, $exceptionHandler, $updateView
|
||||||
} finally {
|
} finally {
|
||||||
$updateView();
|
$updateView();
|
||||||
}
|
}
|
||||||
});
|
}, delay);
|
||||||
};
|
};
|
||||||
}, ['$browser', '$exceptionHandler', '$updateView']);
|
}, ['$browser', '$exceptionHandler', '$updateView']);
|
||||||
|
|
|
||||||
|
|
@ -66,4 +66,11 @@ describe('$defer', function() {
|
||||||
$browser.defer.flush();
|
$browser.defer.flush();
|
||||||
expect(eval).wasCalled();
|
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