-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Drop non-compliant Promises/A+ progress/notify on $q #12533
Comments
Would it be possible to know what library are you trying to use? The extra |
I managed to replace $q with bluebird, and set the scheduler to Bluebird.defer = function() {
var dfd: any = {};
dfd.promise = new Bluebird(function(_resolve, _reject) {
dfd.resolve = _resolve;
dfd.reject = _reject;
dfd.notify = angular.noop;
});
return dfd;
};
var bb: any = Bluebird;
bb.when = Bluebird.resolve.bind(Bluebird);
var originalAll = Bluebird.all;
Bluebird.all = function(promises: any|any[]) {
if (angular.isObject(promises) && !angular.isArray(promises)) {
return Bluebird.props(promises);
} else {
return originalAll.call(Bluebird, promises);
}
};
Bluebird.onPossiblyUnhandledRejection(angular.noop);
function BluebirdConstructor(cb: any): any {
if (!(this instanceof Bluebird)) {
return new Bluebird(cb);
}
return Bluebird;
}
angular.extend(BluebirdConstructor, Bluebird);
$provide.decorator('$q', function() {
return BluebirdConstructor;
});
$q.onPossiblyUnhandledRejection(function(err: any) {
if (__DEBUGGING) {
$log.error(err);
}
});
Bluebird.setScheduler(function(cb) {
$rootScope.$applyAsync(cb);
}); |
I was hit by this problem as well. @pocesar have you been able to fix |
would it be possible to have a plunker that shows the entire problem? |
http://plnkr.co/edit/ITbUfnXOogSdO2r1w52J?p=preview If you remove 'promise' module from dependencies you can see interval ticking as expected The problem seems to be $interval depending on promise progress notification that is no longer part of promises |
@Agamnentzar thanks for the plunker. I think there should be an easy fix. |
btw. a dumb/simplified workaround for app.config(function($provide) {
$provide.decorator('$interval', function($delegate, $rootScope) {
var $newInterval = function(fn, timeout) {
if(arguments.length !== 2 || typeof fn !== 'function' || typeof timeout !== 'number') {
return console.error(new Error('custom $interval supports only 2 arguments, Function and timeout'));
}
var interval = setInterval(function() {
$rootScope.$apply(fn);
}, timeout);
return interval;
};
$newInterval.cancel = function(handle) {
clearInterval(handle);
};
return $newInterval;
});
}); |
Given that dropping the API is a breaking change to $q, it probably is safe to close this issue unless it is desired to remove it completely from the codebase. To fully remove notify usage from $interval would require a breaking change as well (under the assumption someone is hooking into the notifications from the interval promise). Not sure how it is felt, but IMO it probably isn't worth removing since this is a more uncommon case with simple workarounds. |
@lgalfaso, WDYT (since this is assigned to you) ? |
Given that the issue with $interval is fixed, I would close this issue. On Friday, June 3, 2016, Georgios Kalpakas notifications@github.com wrote:
|
Thx @lgalfaso! So, closing this (since we are not going to remove the |
Makes it really hard to replace $q when using a compliant library, since angular uses progress/notify handlers on core itself.
The text was updated successfully, but these errors were encountered: