Skip to content

Commit 32cbf20

Browse files
committed
feat($q): add Promise.progress shorthand for notifyCallbacks
Shorthand method for $q promises that allows attaching a progress callback. Provides the same type of convenience as the existing catch shorthand method, and matches functionality existing in the Q library. This should resolve the only remaining concern addressed in angular#1998 Closes angular#1998
1 parent dba566a commit 32cbf20

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/ng/q.js

+6
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@
103103
*
104104
* - `catch(errorCallback)` – shorthand for `promise.then(null, errorCallback)`
105105
*
106+
* - `progress(notifyCallback)` – shorthand for `promise.then(null, null, notifyCallback)`
107+
*
106108
* - `finally(callback)` – allows you to observe either the fulfillment or rejection of a promise,
107109
* but to do so without modifying the final value. This is useful to release resources or do some
108110
* clean-up that needs to be done whether the promise was rejected or resolved. See the [full
@@ -288,6 +290,10 @@ function qFactory(nextTick, exceptionHandler) {
288290
return this.then(null, callback);
289291
},
290292

293+
progress: function(callback) {
294+
return this.then(null, null, callback);
295+
},
296+
291297
"finally": function(callback) {
292298

293299
function makePromise(value, resolved) {

test/ng/qSpec.js

+13
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,10 @@ describe('q', function() {
524524
expect(typeof promise['finally']).toBe('function');
525525
});
526526

527+
it('should have a progress method', function () {
528+
expect(typeof promise.progress).toBe('function');
529+
});
530+
527531

528532
describe('then', function() {
529533
it('should allow registration of a success callback without an errback or progressback ' +
@@ -923,6 +927,15 @@ describe('q', function() {
923927
expect(logStr()).toBe('error1(foo)->reject(foo); error2(foo)->reject(foo)');
924928
});
925929
});
930+
931+
describe('progress', function () {
932+
it('should be a shorthand for defining promise progress handlers', function() {
933+
promise.progress(progress(1)).then(null, null, progress(2));
934+
deferred.notify('foo');
935+
mockNextTick.flush();
936+
expect(logStr()).toBe('progress1(foo)->foo; progress2(foo)->foo');
937+
})
938+
});
926939
});
927940
});
928941

0 commit comments

Comments
 (0)