[Code Style] Begin refactoring telemetry bundle

Begin refactoring telemetry bundle to use prototype
for methods, WTD-1482.
This commit is contained in:
Victor Woeltjen 2015-08-14 16:14:15 -07:00
parent 365134b085
commit 1ea6f7620e

View File

@ -31,6 +31,32 @@ define(
function () { function () {
"use strict"; "use strict";
/**
* Request telemetry data.
* @param {TelemetryRequest[]} requests and array of
* requests to be handled
* @returns {Promise} a promise for telemetry data
* which may (or may not, depending on
* availability) satisfy the requests
* @method TelemetryService#requestTelemetry
*/
/**
* Subscribe to streaming updates to telemetry data.
* The provided callback will be invoked as new
* telemetry becomes available; as an argument, it
* will receive an object of key-value pairs, where
* keys are source identifiers and values are objects
* of key-value pairs, where keys are point identifiers
* and values are TelemetrySeries objects containing
* the latest streaming telemetry.
* @param {Function} callback the callback to invoke
* @param {TelemetryRequest[]} requests an array of
* requests to be subscribed upon
* @returns {Function} a function which can be called
* to unsubscribe
* @method TelmetryService#subscribe
*/
/** /**
* A telemetry aggregator makes many telemetry providers * A telemetry aggregator makes many telemetry providers
* appear as one. * appear as one.
@ -39,6 +65,9 @@ define(
* @constructor * @constructor
*/ */
function TelemetryAggregator($q, telemetryProviders) { function TelemetryAggregator($q, telemetryProviders) {
this.$q = $q;
this.telemetryProviders = telemetryProviders;
}
// Merge the results from many providers into one // Merge the results from many providers into one
// result object. // result object.
@ -56,15 +85,15 @@ define(
// Request telemetry from all providers; once they've // Request telemetry from all providers; once they've
// responded, merge the results into one result object. // responded, merge the results into one result object.
function requestTelemetry(requests) { TelemetryAggregator.prototype.requestTelemetry = function (requests) {
return $q.all(telemetryProviders.map(function (provider) { return this.$q.all(this.telemetryProviders.map(function (provider) {
return provider.requestTelemetry(requests); return provider.requestTelemetry(requests);
})).then(mergeResults); })).then(mergeResults);
} };
// Subscribe to updates from all providers // Subscribe to updates from all providers
function subscribe(callback, requests) { TelemetryAggregator.prototype.subscribe = function (callback, requests) {
var unsubscribes = telemetryProviders.map(function (provider) { var unsubscribes = this.telemetryProviders.map(function (provider) {
return provider.subscribe(callback, requests); return provider.subscribe(callback, requests);
}); });
@ -77,38 +106,8 @@ define(
} }
}); });
}; };
}
return {
/**
* Request telemetry data.
* @param {TelemetryRequest[]} requests and array of
* requests to be handled
* @returns {Promise} a promise for telemetry data
* which may (or may not, depending on
* availability) satisfy the requests
* @memberof platform/telemetry.TelemetryAggregator#
*/
requestTelemetry: requestTelemetry,
/**
* Subscribe to streaming updates to telemetry data.
* The provided callback will be invoked as new
* telemetry becomes available; as an argument, it
* will receive an object of key-value pairs, where
* keys are source identifiers and values are objects
* of key-value pairs, where keys are point identifiers
* and values are TelemetrySeries objects containing
* the latest streaming telemetry.
* @param {Function} callback the callback to invoke
* @param {TelemetryRequest[]} requests an array of
* requests to be subscribed upon
* @returns {Function} a function which can be called
* to unsubscribe
* @memberof platform/telemetry.TelemetryAggregator#
*/
subscribe: subscribe
}; };
}
return TelemetryAggregator; return TelemetryAggregator;
} }