Skip to content

Commit

Permalink
added conditions for blocking
Browse files Browse the repository at this point in the history
  • Loading branch information
siddarthvader committed Jan 6, 2017
1 parent bb6f7cf commit 23014cf
Showing 1 changed file with 34 additions and 23 deletions.
57 changes: 34 additions & 23 deletions angular-httpshooter.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,24 @@

var flag = true;

console.info($rootScope.httpshooter_queuedCalls);

if (!$rootScope.httpshooter_queuedCalls) {
$rootScope.httpshooter_queuedCalls = [];
}
else{
if (shootConfig.allowDuplicateCalls && $rootScope.httpshooter_queuedCalls.length ) {
if (shootConfig.blockDuplicateCalls && $rootScope.httpshooter_queuedCalls.length ) {

$rootScope.httpshooter_queuedCalls.forEach(function (http, i) {
console.log(http.config.url, config.url, i);
if (http.config.url == config.url) {
flag = false;
if(shootConfig.compareDuplicateParam.url){
if (http.config.url == config.url) {
flag = false;
}
}
if(shootConfig.compareDuplicateParam.data){
if(angular.equals(http.config.data,config.data)){
flag=false;
}
}
});
}
Expand Down Expand Up @@ -100,7 +109,7 @@
callDeterminer();
}
};

var get = function (config,time) {

var deferred = $rootScope.httpshooter_queuedCalls[0].deferred;
Expand Down Expand Up @@ -141,11 +150,11 @@
data: config.data,
timeout: timeout
}).then(function (data) {

success(data.data);

}, function (data) {

fail(data.data);

}).finally(function () {
Expand All @@ -171,11 +180,11 @@
}).then(function (data) {

success(data.data);

}, function (data) {

fail(data.data);

}).finally(function () {
$timeout.cancel(timeout);
});
Expand All @@ -197,20 +206,20 @@
data: config.data,
timeout: timeout
}).then(function (data) {

success(data.data);

}, function (data) {

fail(data.data);

}).finally(function () {
$timeout.cancel(timeout);
});

};


var deleteCall = function (config, time) {

var deferred = $rootScope.httpshooter_queuedCalls[0].deferred;
Expand All @@ -231,9 +240,9 @@


}, function (data) {

fail(data.data);

}).finally(function () {
$timeout.cancel(timeout);
});
Expand All @@ -253,27 +262,29 @@
method: 'HEAD',
timeout: timeout
}).then(function (data) {

success(data.data);

}, function (data) {

fail(data.data);

}).finally(function () {
$timeout.cancel(timeout);
});
};

return {
queue: queue
};

}

angular.module('angular-httpshooter').constant('shootConfig', {
allowDuplicateCalls: true,
defaultTimeOut:36000
blockDuplicateCalls: true,
compareDuplicateParam:{
url:true,
data:false
}
});

})();
Expand Down

0 comments on commit 23014cf

Please sign in to comment.