Skip to content

Commit b5abe65

Browse files
authored
Merge pull request nasa#1488 from nasa/open1480
Modified MSL data source to use a single cached connection
2 parents 616aab4 + a591774 commit b5abe65

File tree

2 files changed

+6
-16
lines changed

2 files changed

+6
-16
lines changed

example/msl/bundle.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ define([
9292
{
9393
"key":"rems.adapter",
9494
"implementation": RemsTelemetryServerAdapter,
95-
"depends": ["$q", "$http", "$log", "REMS_WS_URL"]
95+
"depends": ["$http", "$log", "REMS_WS_URL"]
9696
}
9797
],
9898
"components": [

example/msl/src/RemsTelemetryServerAdapter.js

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,12 @@ define(
4242
* @param REMS_WS_URL The location of the REMS telemetry data.
4343
* @constructor
4444
*/
45-
function RemsTelemetryServerAdapter($q, $http, $log, REMS_WS_URL) {
45+
function RemsTelemetryServerAdapter($http, $log, REMS_WS_URL) {
4646
this.localDataURI = module.uri.substring(0, module.uri.lastIndexOf('/') + 1) + LOCAL_DATA;
47-
this.deferreds = {};
4847
this.REMS_WS_URL = REMS_WS_URL;
49-
this.$q = $q;
5048
this.$http = $http;
5149
this.$log = $log;
52-
this.cache = undefined;
50+
this.promise = undefined;
5351
}
5452

5553
/**
@@ -65,15 +63,10 @@ define(
6563
*/
6664
RemsTelemetryServerAdapter.prototype.requestHistory = function(request) {
6765
var self = this,
68-
id = request.key,
69-
deferred = this.$q.defer();
66+
id = request.key;
7067

7168
function processResponse(response){
7269
var data = [];
73-
/*
74-
* Currently all data is returned for entire history of the mission. Cache response to avoid unnecessary re-queries.
75-
*/
76-
self.cache = response;
7770
/*
7871
* History data is organised by Sol. Iterate over sols...
7972
*/
@@ -110,17 +103,15 @@ define(
110103
}
111104

112105
function packageAndResolve(results){
113-
deferred.resolve({id: id, values: results});
106+
return {id: id, values: results};
114107
}
115108

116109

117-
this.$q.when(this.cache || this.$http.get(this.REMS_WS_URL))
110+
return (this.promise = this.promise || this.$http.get(this.REMS_WS_URL))
118111
.catch(fallbackToLocal)
119112
.then(processResponse)
120113
.then(filterResults)
121114
.then(packageAndResolve);
122-
123-
return deferred.promise;
124115
};
125116

126117
/**
@@ -132,7 +123,6 @@ define(
132123
* @returns {Promise | Array<RemsTelemetryValue>} that resolves with an Array of {@link RemsTelemetryValue} objects for the request data key.
133124
*/
134125
RemsTelemetryServerAdapter.prototype.history = function(request) {
135-
var id = request.key;
136126
return this.requestHistory(request);
137127
};
138128

0 commit comments

Comments
 (0)