Skip to content
Extraits de code Groupes Projets
Valider 5578a549 rédigé par diosmosis's avatar diosmosis Validation de Thomas Steur
Parcourir les fichiers

Fixes #6086, in piwikApi angularjs object, make sure we use and add abort()...

Fixes #6086, in piwikApi angularjs object, make sure we use and add abort() method to new promises returned by angularjs promise methods.
parent d9f1dff7
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -90,28 +90,29 @@ angular.module('piwikApp.service').factory('piwikApi', function ($http, $q, $roo ...@@ -90,28 +90,29 @@ angular.module('piwikApp.service').factory('piwikApi', function ($http, $q, $roo
// we can't modify requestPromise directly and add an abort method since for some reason it gets // we can't modify requestPromise directly and add an abort method since for some reason it gets
// removed after then/finally/catch is called. // removed after then/finally/catch is called.
var request = { var addAbortMethod = function (to) {
then: function () { return {
requestPromise.then.apply(requestPromise, arguments); then: function () {
return this; return addAbortMethod(to.then.apply(to, arguments));
}, },
'finally': function () { 'finally': function () {
requestPromise['finally'].apply(requestPromise, arguments); return addAbortMethod(to['finally'].apply(to, arguments));
return this; },
},
'catch': function () {
'catch': function () { return addAbortMethod(to['catch'].apply(to, arguments));
requestPromise['catch'].apply(requestPromise, arguments); },
return this;
}, abort: function () {
deferred.reject();
abort: function () { return this;
deferred.reject(); }
return this; };
}
}; };
var request = addAbortMethod(requestPromise);
allRequests.push(request); allRequests.push(request);
return request; return request;
......
...@@ -46,8 +46,11 @@ describe('piwikApiClient', function () { ...@@ -46,8 +46,11 @@ describe('piwikApiClient', function () {
method: "SomePlugin.action" method: "SomePlugin.action"
}).then(function (response) { }).then(function (response) {
firstThenDone = true; firstThenDone = true;
return "newval";
}).then(function (response) { }).then(function (response) {
expect(firstThenDone).to.equal(true); expect(firstThenDone).to.equal(true);
expect(response).to.equal("newval");
done(); done();
}).catch(function (ex) { }).catch(function (ex) {
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter