Skip to content

Commit

Permalink
Merge pull request #31 from unicef-polymer/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
adi130987 authored Nov 7, 2017
2 parents d014fe5 + b1eb7a2 commit 3677e21
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "etools-ajax",
"description": "Polymer element and behavior for handling ajax requests",
"version": "2.0.2",
"version": "2.0.3",
"license": "https://github.com/unicef-polymer/etools-ajax/blob/master/LICENSE.md",
"main": "etools-ajax-request.html",
"dependencies": {
Expand Down
4 changes: 3 additions & 1 deletion etools-ajax-cache-behavior.html
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@
// add list expire mapping details
listsExpireMapTable.put(listExpireDetails);
// save bulk data
specifiedTable.bulkPut(responseData);
specifiedTable.clear().then(function() {
specifiedTable.bulkAdd(responseData);
});
}).then(function(result) {
// request response saved into specified table
// transaction succeeded
Expand Down
30 changes: 21 additions & 9 deletions etools-ajax-request-behavior.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
// return it without making the request
return this.getEndpointDataFromCache(cachingInfo).then(function(response) {
if (!response) {
return self._doRequest(reqConfigOptions, cachingInfo, reqConfig.checkProgress);
return self._doRequest(reqConfigOptions, cachingInfo, reqConfig.checkProgress, activeReqKey);
}
return response;
});
Expand Down Expand Up @@ -126,7 +126,7 @@

_removeActiveRequestFromList: function(key) {
if (key) {
var req = this._getActiveRequestByKey(key);
var req = this.getActiveRequestByKey(key);
if (req) {
var requestIndex = this.activeAjaxRequests.indexOf(req);
if (requestIndex > -1) {
Expand All @@ -136,20 +136,32 @@
}
},

_getActiveRequestByKey: function(key) {
getActiveRequestByKey: function(key) {
return this.activeAjaxRequests.find(function(activeReqMapObj) {
return activeReqMapObj.key === key;
});
},

abortRequest: function(key) {
// abort last request if key is not provided
var req = this.lastAjaxRequest;
abortRequestByKey: function(key) {
// abort request by key
if (key) {
req = this._getActiveRequestByKey(key);
var activeReq = this.getActiveRequestByKey(key);
if (activeReq) {
this.abortActiveRequest(activeReq);
} else {
this.logWarn('No active request found by this key: ' + key + '.',
'EtoolsAjaxRequestBehavior:abortRequest');
}
} else {
this.logWarn('Aborting request by key requires a key.', 'EtoolsAjaxRequestBehavior:abortRequestByKey');
}
if (req) {
req.abort();
},

abortActiveRequest: function(activeReqMapObj) {
if (activeReqMapObj && activeReqMapObj.request) {
activeReqMapObj.request.abort();
} else {
this.logWarn('There is no request to abort.' , 'EtoolsAjaxRequestBehavior:abortActiveRequest');
}
},

Expand Down

0 comments on commit 3677e21

Please sign in to comment.