forked from angular/angular.js
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(core): create a wrapper to manage async callbacks
- Loading branch information
Showing
5 changed files
with
63 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict'; | ||
|
||
function $$AsyncCallbackProvider(){ | ||
this.$get = ['$$rAF', '$timeout', function($$rAF, $timeout) { | ||
return $$rAF.supported | ||
? function(fn) { return $$rAF(fn); } | ||
: function(fn) { | ||
return $timeout(fn, 0, false); | ||
}; | ||
}]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use strict'; | ||
describe('$$asyncCallback', function() { | ||
it('should perform a callback asynchronously', inject(function($$asyncCallback) { | ||
var message = 'hello there '; | ||
$$asyncCallback(function() { | ||
message += 'Angular'; | ||
}); | ||
|
||
expect(message).toBe('hello there '); | ||
$$asyncCallback.flush(); | ||
expect(message).toBe('hello there Angular'); | ||
})); | ||
|
||
describe('mocks', function() { | ||
it('should queue up all async callbacks', inject(function($$asyncCallback) { | ||
var callback = jasmine.createSpy('callback'); | ||
$$asyncCallback(callback); | ||
$$asyncCallback(callback); | ||
$$asyncCallback(callback); | ||
expect(callback.callCount).toBe(0); | ||
|
||
$$asyncCallback.flush(); | ||
expect(callback.callCount).toBe(3); | ||
|
||
$$asyncCallback(callback); | ||
$$asyncCallback(callback); | ||
expect(callback.callCount).toBe(3); | ||
|
||
$$asyncCallback.flush(); | ||
expect(callback.callCount).toBe(5); | ||
})); | ||
}); | ||
}); |