Refactor logic into _updateAppCache

This commit is contained in:
Girish Ramakrishnan
2018-06-26 08:41:25 -07:00
parent e3e62b8407
commit 24ca5bc990

View File

@@ -1089,6 +1089,29 @@ angular.module('Application').service('Client', ['$http', '$interval', 'md5', 'N
return app;
};
Client.prototype._updateAppCache = function (app) {
var found = -1;
for (var i = 0; i < this._installedApps.length; ++i) {
if (this._installedApps[i].id === app.id) {
found = i;
break;
}
}
var tmp = {};
angular.copy(app, tmp);
this._appPostProcess(tmp);
// only replace if the app is already known
if (found !== -1) {
angular.copy(tmp, this._installedApps[found]);
} else {
this._installedApps.push(tmp);
}
};
Client.prototype.refreshInstalledApps = function (callback) {
var that = this;
@@ -1100,28 +1123,7 @@ angular.module('Application').service('Client', ['$http', '$interval', 'md5', 'N
if (error) return callback(error);
// insert or update new apps
apps.forEach(function (app) {
var found = false;
for (var i = 0; i < that._installedApps.length; ++i) {
if (that._installedApps[i].id === app.id) {
found = i;
break;
}
}
var tmp = {};
angular.copy(app, tmp);
that._appPostProcess(tmp);
// only replace if the app is already known
if (found !== false) {
angular.copy(tmp, that._installedApps[found]);
} else {
that._installedApps.push(tmp);
}
});
apps.forEach(that._updateAppCache.bind(that));
// filter out old entries, going backwards to allow splicing
for(var i = that._installedApps.length - 1; i >= 0; --i) {