From 9af7a9198e2d30608ea6c40eedde03e44a6ef569 Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Tue, 12 Jun 2012 00:35:28 -0700 Subject: fix($defer): remove deprecated $defer service --- angularFiles.js | 1 - .../dev_guide.services.managing_dependencies.ngdoc | 6 +- docs/content/guide/scope.ngdoc | 2 +- src/AngularPublic.js | 1 - src/bootstrap/bootstrap-prettify.js | 2 +- src/ng/defer.js | 49 --------- src/ngMock/angular-mocks.js | 5 - test/ng/deferSpec.js | 114 --------------------- test/ngMock/angular-mocksSpec.js | 2 +- 9 files changed, 6 insertions(+), 176 deletions(-) delete mode 100644 src/ng/defer.js delete mode 100644 test/ng/deferSpec.js diff --git a/angularFiles.js b/angularFiles.js index e82362cf..70502b04 100644 --- a/angularFiles.js +++ b/angularFiles.js @@ -13,7 +13,6 @@ angularFiles = { 'src/ng/cacheFactory.js', 'src/ng/compile.js', 'src/ng/controller.js', - 'src/ng/defer.js', 'src/ng/document.js', 'src/ng/exceptionHandler.js', 'src/ng/interpolate.js', diff --git a/docs/content/guide/dev_guide.services.managing_dependencies.ngdoc b/docs/content/guide/dev_guide.services.managing_dependencies.ngdoc index 54d7a5d1..e6f6aa43 100644 --- a/docs/content/guide/dev_guide.services.managing_dependencies.ngdoc +++ b/docs/content/guide/dev_guide.services.managing_dependencies.ngdoc @@ -50,7 +50,7 @@ provided by Angular's web framework: * @param {*} message Message to be logged. */ function batchLogModule($provide){ - $provide.factory('batchLog', ['$defer', '$log', function($defer, $log) { + $provide.factory('batchLog', ['$timeout', '$log', function($timeout, $log) { var messageQueue = []; function log() { @@ -58,7 +58,7 @@ provided by Angular's web framework: $log('batchLog messages: ', messageQueue); messageQueue = []; } - $defer(log, 50000); + $timeout(log, 50000); } // start periodic checking @@ -88,7 +88,7 @@ provided by Angular's web framework: Things to notice in this example: -* The `batchLog` service depends on the built-in {@link api/ng.$defer $defer} and +* The `batchLog` service depends on the built-in {@link api/ng.$timeout $timeout} and {@link api/ng.$log $log} services, and allows messages to be logged into the `console.log` in batches. * The `routeTemplateMonitor` service depends on the built-in {@link api/ng.$route diff --git a/docs/content/guide/scope.ngdoc b/docs/content/guide/scope.ngdoc index ac0089c9..5b2c08ab 100644 --- a/docs/content/guide/scope.ngdoc +++ b/docs/content/guide/scope.ngdoc @@ -259,7 +259,7 @@ the `$digest` phase. This delay is desirable, since it coalesces multiple model api/ng.$rootScope.Scope#$apply scope.$apply()}. (Angular apis do this implicitly, so no extra `$apply` call is needed when doing synchronous work in controllers, or asynchronous work with {@link api/ng.$http $http} or {@link - api/ng.$defer $defer} services. + api/ng.$timeout $timeout} services. 4. **Mutation observation** diff --git a/src/AngularPublic.js b/src/AngularPublic.js index 54536b43..61c77af3 100644 --- a/src/AngularPublic.js +++ b/src/AngularPublic.js @@ -109,7 +109,6 @@ function publishExternalAPI(angular){ $browser: $BrowserProvider, $cacheFactory: $CacheFactoryProvider, $controller: $ControllerProvider, - $defer: $DeferProvider, $document: $DocumentProvider, $exceptionHandler: $ExceptionHandlerProvider, $filter: $FilterProvider, diff --git a/src/bootstrap/bootstrap-prettify.js b/src/bootstrap/bootstrap-prettify.js index a4eb52f2..b458c832 100644 --- a/src/bootstrap/bootstrap-prettify.js +++ b/src/bootstrap/bootstrap-prettify.js @@ -198,7 +198,7 @@ directive.ngEmbedApp = ['$templateCache', '$browser', '$rootScope', '$location', }]; this.html5Mode = angular.noop; }); - $provide.decorator('$defer', ['$rootScope', '$delegate', function($rootScope, $delegate) { + $provide.decorator('$timeout', ['$rootScope', '$delegate', function($rootScope, $delegate) { return angular.extend(function(fn, delay) { if (delay && delay > 50) { return setTimeout(function() { diff --git a/src/ng/defer.js b/src/ng/defer.js deleted file mode 100644 index 850d9cf5..00000000 --- a/src/ng/defer.js +++ /dev/null @@ -1,49 +0,0 @@ -'use strict'; - -/** - * @ngdoc function - * @name ng.$defer - * @deprecated Made obsolete by $timeout service. Please migrate your code. This service will be - * removed with 1.0 final. - * @requires $browser - * - * @description - * Delegates to {@link ng.$browser#defer $browser.defer}, but wraps the `fn` function - * into a try/catch block and delegates any exceptions to - * {@link ng.$exceptionHandler $exceptionHandler} service. - * - * 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. - * @returns {*} DeferId that can be used to cancel the task via `$defer.cancel()`. - */ - -/** - * @ngdoc function - * @name ng.$defer#cancel - * @methodOf ng.$defer - * - * @description - * Cancels a defered task identified with `deferId`. - * - * @param {*} deferId Token returned by the `$defer` function. - * @returns {boolean} Returns `true` if the task hasn't executed yet and was successfuly canceled. - */ -function $DeferProvider(){ - this.$get = ['$rootScope', '$browser', '$log', function($rootScope, $browser, $log) { - $log.warn('$defer service has been deprecated, migrate to $timeout'); - - function defer(fn, delay) { - return $browser.defer(function() { - $rootScope.$apply(fn); - }, delay); - } - - defer.cancel = function(deferId) { - return $browser.defer.cancel(deferId); - }; - - return defer; - }]; -} diff --git a/src/ngMock/angular-mocks.js b/src/ngMock/angular-mocks.js index 7d11a99d..f1b2223b 100644 --- a/src/ngMock/angular-mocks.js +++ b/src/ngMock/angular-mocks.js @@ -27,11 +27,6 @@ angular.mock = {}; * * The api of this service is the same as that of the real {@link ng.$browser $browser}, except * that there are several helper methods available which can be used in tests. - * - * The following apis can be used in tests: - * - * - $browser.defer — enables testing of code that uses - * {@link ng.$defer $defer} for executing functions via the `setTimeout` api. */ angular.mock.$BrowserProvider = function() { this.$get = function(){ diff --git a/test/ng/deferSpec.js b/test/ng/deferSpec.js deleted file mode 100644 index 2e31aadb..00000000 --- a/test/ng/deferSpec.js +++ /dev/null @@ -1,114 +0,0 @@ -'use strict'; - -describe('$defer', function() { - beforeEach(module(function($provide) { - $provide.factory('$exceptionHandler', function(){ - return jasmine.createSpy('$exceptionHandler'); - }); - $provide.value('$log', {warn: noop}); - })); - - - it('should delegate functions to $browser.defer', inject(function($defer, $browser, $exceptionHandler) { - var counter = 0; - $defer(function() { counter++; }); - - expect(counter).toBe(0); - - $browser.defer.flush(); - expect(counter).toBe(1); - - expect(function() {$browser.defer.flush();}).toThrow('No deferred tasks to be flushed'); - expect(counter).toBe(1); - - expect($exceptionHandler).not.toHaveBeenCalled(); - })); - - - it('should delegate exception to the $exceptionHandler service', inject(function($defer, $browser, $exceptionHandler) { - $defer(function() {throw "Test Error";}); - expect($exceptionHandler).not.toHaveBeenCalled(); - - $browser.defer.flush(); - expect($exceptionHandler).toHaveBeenCalledWith("Test Error"); - })); - - - it('should call $apply after each callback is executed', inject(function($defer, $browser, $rootScope) { - var applySpy = this.spyOn($rootScope, '$apply').andCallThrough(); - - $defer(function() {}); - expect(applySpy).not.toHaveBeenCalled(); - - $browser.defer.flush(); - expect(applySpy).toHaveBeenCalled(); - - applySpy.reset(); //reset the spy; - - $defer(function() {}); - $defer(function() {}); - $browser.defer.flush(); - expect(applySpy.callCount).toBe(2); - })); - - - it('should call $apply even if an exception is thrown in callback', inject(function($defer, $browser, $rootScope) { - var applySpy = this.spyOn($rootScope, '$apply').andCallThrough(); - - $defer(function() {throw "Test Error";}); - expect(applySpy).not.toHaveBeenCalled(); - - $browser.defer.flush(); - expect(applySpy).toHaveBeenCalled(); - })); - - - it('should allow you to specify the delay time', inject(function($defer, $browser) { - var defer = this.spyOn($browser, 'defer'); - $defer(noop, 123); - expect(defer.callCount).toEqual(1); - expect(defer.mostRecentCall.args[1]).toEqual(123); - })); - - - it('should return a cancelation token', inject(function($defer, $browser) { - var defer = this.spyOn($browser, 'defer').andReturn('xxx'); - expect($defer(noop)).toEqual('xxx'); - })); - - - describe('cancel', function() { - it('should cancel tasks', inject(function($defer, $browser) { - var task1 = jasmine.createSpy('task1'), - task2 = jasmine.createSpy('task2'), - task3 = jasmine.createSpy('task3'), - token1, token3; - - token1 = $defer(task1); - $defer(task2); - token3 = $defer(task3, 333); - - $defer.cancel(token3); - $defer.cancel(token1); - $browser.defer.flush(); - - expect(task1).not.toHaveBeenCalled(); - expect(task2).toHaveBeenCalledOnce(); - expect(task3).not.toHaveBeenCalled(); - })); - - - it('should return true if a task was succesffuly canceled', inject(function($defer, $browser) { - var task1 = jasmine.createSpy('task1'), - task2 = jasmine.createSpy('task2'), - token1, token2; - - token1 = $defer(task1); - $browser.defer.flush(); - token2 = $defer(task2); - - expect($defer.cancel(token1)).toBe(false); - expect($defer.cancel(token2)).toBe(true); - })); - }); -}); diff --git a/test/ngMock/angular-mocksSpec.js b/test/ngMock/angular-mocksSpec.js index f4f6a346..5992846d 100644 --- a/test/ngMock/angular-mocksSpec.js +++ b/test/ngMock/angular-mocksSpec.js @@ -989,7 +989,7 @@ describe('ngMockE2E', function() { describe('autoflush', function() { - it('should flush responses via $defer', inject(function($browser) { + it('should flush responses via $browser.defer', inject(function($browser) { hb.when('GET', '/foo').respond('bar'); hb('GET', '/foo', null, callback); -- cgit v1.2.3