Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 3ef5298

Browse files
Ryan Dalepetebacondarwin
Ryan Dale
authored andcommitted
feat($q): $q.resolve as an alias for $q.when
New "when" alias "resolve" to maintain naming consistency with ES6. Closes #11944 Closes #11987
1 parent 291d7c4 commit 3ef5298

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/ng/q.js

+14
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,19 @@ function qFactory(nextTick, exceptionHandler) {
497497
return result.promise.then(callback, errback, progressBack);
498498
};
499499

500+
/**
501+
* @ngdoc method
502+
* @name $q#resolve
503+
* @kind function
504+
*
505+
* @description
506+
* Alias of {@link ng.$q#when when} to maintain naming consistency with ES6.
507+
*
508+
* @param {*} value Value or a promise
509+
* @returns {Promise} Returns a promise of the passed value or promise
510+
*/
511+
var resolve = when;
512+
500513
/**
501514
* @ngdoc method
502515
* @name $q#all
@@ -565,6 +578,7 @@ function qFactory(nextTick, exceptionHandler) {
565578
$Q.defer = defer;
566579
$Q.reject = reject;
567580
$Q.when = when;
581+
$Q.resolve = resolve;
568582
$Q.all = all;
569583

570584
return $Q;

test/ng/qSpec.js

+8
Original file line numberDiff line numberDiff line change
@@ -1643,6 +1643,14 @@ describe('q', function() {
16431643
});
16441644

16451645

1646+
describe('resolve', function() {
1647+
it('should be an alias of the "when" function', function() {
1648+
expect(q.resolve).toBeDefined();
1649+
expect(q.resolve).toEqual(q.when);
1650+
});
1651+
});
1652+
1653+
16461654
describe('optional callbacks', function() {
16471655
it('should not require success callback and propagate resolution', function() {
16481656
q.when('hi', null, error()).then(success(2), error());

0 commit comments

Comments
 (0)