Skip to content

Commit faafeb8

Browse files
committed
feat(common): prevents $then to wait for a digest cycle when last promise is resolved.
1 parent 4116cb8 commit faafeb8

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/module/api/common-api.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ RMModule.factory('RMCommonApi', ['$http', '$q', '$log', function($http, $q, $log
283283
*/
284284
$then: function(_success, _error) {
285285

286-
if(!this.$promise) { // TODO: $promise is resolved...
286+
if(!this.$promise || this.$promise === this.$$lastResolved) {
287287
// if there is no pending promise, just execute success callback,
288288
// if callback returns a promise, then set it as the current promise.
289289
this.$last = null;
@@ -296,6 +296,14 @@ RMModule.factory('RMCommonApi', ['$http', '$q', '$log', function($http, $q, $log
296296
);
297297
}
298298

299+
if(this.$promise) {
300+
// little optimization: keep an eye on last resolved promise!
301+
var promise = this.$promise, _this = this;
302+
this.$promise['finally'](function() {
303+
_this.$$lastResolved = promise;
304+
});
305+
}
306+
299307
return this;
300308
},
301309

0 commit comments

Comments
 (0)