Merge pull request #27 from zendesk/alistair/actually_fix_double_count_bug

[APPS-1392] Actually fix double count bug
This commit is contained in:
Alistair Roche 2014-05-07 11:38:41 +10:00
Родитель 09cfa31d0d a26501e7a5
Коммит a1e3b1745c
1 изменённых файлов: 5 добавлений и 19 удалений

24
app.js
Просмотреть файл

@ -125,12 +125,8 @@
},
countedAjax: function() {
var request = this.ajax.apply(this, arguments);
this.storage.requestsCount++;
this.storage.outstandingRequests.push(request);
return request.always((function() {
var index = this.storage.outstandingRequests.indexOf(request);
this.storage.outstandingRequests.splice(index, 1);
return this.ajax.apply(this, arguments).always((function() {
_.defer((this.finishedAjax).bind(this));
}).bind(this));
},
@ -141,15 +137,6 @@
}
},
cancelOutstandingRequests: function () {
if (this.storage && this.storage.outstandingRequests) {
this.storage.outstandingRequests.forEach(function(ajax) {
ajax.abort();
});
this.storage.outstandingRequests = [];
}
},
fieldsForCurrent: function(target, fields, selected, values) {
return _.compact(_.map(selected, (function(key) {
var field = _.find(fields, function(field) {
@ -253,8 +240,8 @@
// EVENTS ==================================================================
onAppActivation: function() {
this.cancelOutstandingRequests();
// we use throttle because of race conditions when this fires twice in quick succession
onAppActivation: _.throttle(function() {
var defaultStorage = {
user: null,
ticketsCounters: {},
@ -263,8 +250,7 @@
fields: [],
selectedKeys: [],
orgFieldsActivated: false,
tickets: [],
outstandingRequests: []
tickets: []
};
this.storage = _.clone(defaultStorage); // not sure the clone is needed here
this.storage.orgFieldsActivated = (this.setting('orgFieldsActivated') == 'true');
@ -286,7 +272,7 @@
this.switchTo('empty');
}
}).bind(this));
},
}, 300, {leading: false}),
onRequestsFinished: function() {
if (!this.storage.user) return;