diff options
author | diosmosis <benakamoorthi@fastmail.fm> | 2014-09-01 03:10:05 +0400 |
---|---|---|
committer | Thomas Steur <thomas.steur@googlemail.com> | 2014-09-01 20:12:43 +0400 |
commit | 5578a54985282e6da3e3cc2c1b2d1532c91fabd7 (patch) | |
tree | 7fd4e09cbcfda7866536b567a2202ea739f6fb86 | |
parent | d9f1dff76415bd28ee2d68f2627aa14d9782815d (diff) |
Fixes #6086, in piwikApi angularjs object, make sure we use and add abort() method to new promises returned by angularjs promise methods.
-rw-r--r-- | plugins/CoreHome/angularjs/common/services/piwik-api.js | 41 | ||||
-rw-r--r-- | plugins/CoreHome/angularjs/common/services/piwik-api_spec.js | 3 |
2 files changed, 24 insertions, 20 deletions
diff --git a/plugins/CoreHome/angularjs/common/services/piwik-api.js b/plugins/CoreHome/angularjs/common/services/piwik-api.js index 3830d657e8..bd5cfee4a2 100644 --- a/plugins/CoreHome/angularjs/common/services/piwik-api.js +++ b/plugins/CoreHome/angularjs/common/services/piwik-api.js @@ -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 // removed after then/finally/catch is called. - var request = { - then: function () { - requestPromise.then.apply(requestPromise, arguments); - return this; - }, - - 'finally': function () { - requestPromise['finally'].apply(requestPromise, arguments); - return this; - }, - - 'catch': function () { - requestPromise['catch'].apply(requestPromise, arguments); - return this; - }, - - abort: function () { - deferred.reject(); - return this; - } + var addAbortMethod = function (to) { + return { + then: function () { + return addAbortMethod(to.then.apply(to, arguments)); + }, + + 'finally': function () { + return addAbortMethod(to['finally'].apply(to, arguments)); + }, + + 'catch': function () { + return addAbortMethod(to['catch'].apply(to, arguments)); + }, + + abort: function () { + deferred.reject(); + return this; + } + }; }; + var request = addAbortMethod(requestPromise); + allRequests.push(request); return request; diff --git a/plugins/CoreHome/angularjs/common/services/piwik-api_spec.js b/plugins/CoreHome/angularjs/common/services/piwik-api_spec.js index e5d547ce9e..fecf56cde8 100644 --- a/plugins/CoreHome/angularjs/common/services/piwik-api_spec.js +++ b/plugins/CoreHome/angularjs/common/services/piwik-api_spec.js @@ -46,8 +46,11 @@ describe('piwikApiClient', function () { method: "SomePlugin.action" }).then(function (response) { firstThenDone = true; + + return "newval"; }).then(function (response) { expect(firstThenDone).to.equal(true); + expect(response).to.equal("newval"); done(); }).catch(function (ex) { |