[Code Style] Use prototypes in telemetry bundle

WTD-1482
This commit is contained in:
Victor Woeltjen
2015-08-14 16:47:20 -07:00
parent 1ea6f7620e
commit 2ccca016a5
9 changed files with 443 additions and 461 deletions

View File

@ -42,38 +42,39 @@ define(
* at the specific data which is appropriate to the domain object.) * at the specific data which is appropriate to the domain object.)
* *
* @memberof platform/telemetry * @memberof platform/telemetry
* @implements {Capability}
* @constructor * @constructor
*/ */
function TelemetryCapability($injector, $q, $log, domainObject) { function TelemetryCapability($injector, $q, $log, domainObject) {
var telemetryService,
subscriptions = [],
unsubscribeFunction;
// We could depend on telemetryService directly, but // We could depend on telemetryService directly, but
// there isn't a platform implementation of this; // there isn't a platform implementation of this.
function getTelemetryService() { this.initializeTelemetryService = function () {
if (telemetryService === undefined) {
try { try {
telemetryService = return (this.telemetryService =
$injector.get("telemetryService"); $injector.get("telemetryService"));
} catch (e) { } catch (e) {
// $injector should throw if telemetryService // $injector should throw if telemetryService
// is unavailable or unsatisfiable. // is unavailable or unsatisfiable.
$log.warn("Telemetry service unavailable"); $log.warn("Telemetry service unavailable");
telemetryService = null; return (this.telemetryService = null);
} }
} };
return telemetryService;
this.$q = $q;
this.$log = $log;
this.domainObject = domainObject;
} }
// Build a request object. This takes the request that was // Build a request object. This takes the request that was
// passed to the capability, and adds source, id, and key // passed to the capability, and adds source, id, and key
// fields associated with the object (from its type definition // fields associated with the object (from its type definition
// and/or its model) // and/or its model)
function buildRequest(request) { TelemetryCapability.prototype.buildRequest = function (request) {
// Start with any "telemetry" field in type; use that as a // Start with any "telemetry" field in type; use that as a
// basis for the request. // basis for the request.
var type = domainObject.getCapability("type"), var domainObject = this.domainObject,
type = domainObject.getCapability("type"),
typeRequest = (type && type.getDefinition().telemetry) || {}, typeRequest = (type && type.getDefinition().telemetry) || {},
modelTelemetry = domainObject.getModel().telemetry, modelTelemetry = domainObject.getModel().telemetry,
fullRequest = Object.create(typeRequest); fullRequest = Object.create(typeRequest);
@ -98,14 +99,23 @@ define(
} }
return fullRequest; return fullRequest;
} };
// Issue a request for telemetry data
function requestTelemetry(request) { /**
* Request telemetry data for this specific domain object.
* @param {TelemetryRequest} [request] parameters for this
* specific request
* @returns {Promise} a promise for the resulting telemetry
* object
*/
TelemetryCapability.prototype.requestData = function requestTelemetry(request) {
// Bring in any defaults from the object model // Bring in any defaults from the object model
var fullRequest = buildRequest(request || {}), var fullRequest = this.buildRequest(request || {}),
source = fullRequest.source, source = fullRequest.source,
key = fullRequest.key; key = fullRequest.key,
telemetryService = this.telemetryService ||
this.initializeTelemetryService(); // Lazy initialization
// Pull out the relevant field from the larger, // Pull out the relevant field from the larger,
// structured response. // structured response.
@ -122,14 +132,36 @@ define(
// If a telemetryService is not available, // If a telemetryService is not available,
// getTelemetryService() should reject, and this should // getTelemetryService() should reject, and this should
// bubble through subsequent then calls. // bubble through subsequent then calls.
return getTelemetryService() && return telemetryService &&
requestTelemetryFromService() requestTelemetryFromService().then(getRelevantResponse);
.then(getRelevantResponse); };
}
// Listen for real-time and/or streaming updates /**
function subscribe(callback, request) { * Get metadata about this domain object's associated
var fullRequest = buildRequest(request || {}); * telemetry.
* @returns {TelemetryMetadata} metadata about this object's telemetry
*/
TelemetryCapability.prototype.getMetadata = function () {
// metadata just looks like a request,
// so use buildRequest to bring in both
// type-level and object-level telemetry
// properties
return (this.metadata = this.metadata || this.buildRequest({}));
};
/**
* Subscribe to updates to telemetry data for this domain
* object.
* @param {Function} callback a function to call when new
* data becomes available; the telemetry series
* containing the data will be given as an argument.
* @param {TelemetryRequest} [request] parameters for the
* subscription request
*/
TelemetryCapability.prototype.subscribe = function subscribe(callback, request) {
var fullRequest = this.buildRequest(request || {}),
telemetryService = this.telemetryService ||
this.initializeTelemetryService(); // Lazy initialization
// Unpack the relevant telemetry series // Unpack the relevant telemetry series
function update(telemetries) { function update(telemetries) {
@ -141,55 +173,16 @@ define(
} }
} }
return getTelemetryService() && return telemetryService &&
telemetryService.subscribe(update, [fullRequest]); telemetryService.subscribe(update, [fullRequest]);
}
return {
/**
* Request telemetry data for this specific domain object.
* @param {TelemetryRequest} [request] parameters for this
* specific request
* @returns {Promise} a promise for the resulting telemetry
* object
* @memberof platform/telemetry.TelemetryCapability#
*/
requestData: requestTelemetry,
/**
* Get metadata about this domain object's associated
* telemetry.
* @memberof platform/telemetry.TelemetryCapability#
*/
getMetadata: function () {
// metadata just looks like a request,
// so use buildRequest to bring in both
// type-level and object-level telemetry
// properties
return buildRequest({});
},
/**
* Subscribe to updates to telemetry data for this domain
* object.
* @param {Function} callback a function to call when new
* data becomes available; the telemetry series
* containing the data will be given as an argument.
* @param {TelemetryRequest} [request] parameters for the
* subscription request
* @memberof platform/telemetry.TelemetryCapability#
*/
subscribe: subscribe
}; };
}
/** /**
* The telemetry capability is applicable when a * The telemetry capability is applicable when a
* domain object model has a "telemetry" field. * domain object model has a "telemetry" field.
*/ */
TelemetryCapability.appliesTo = function (model) { TelemetryCapability.appliesTo = function (model) {
return (model && return (model && model.telemetry) ? true : false;
model.telemetry) ? true : false;
}; };
return TelemetryCapability; return TelemetryCapability;

View File

@ -36,6 +36,7 @@ define(
* *
* @memberof platform/telemetry * @memberof platform/telemetry
* @constructor * @constructor
* @deprecated use platform/telemetry.TelemetryHandler instead
*/ */
function TelemetryController($scope, $q, $timeout, $log) { function TelemetryController($scope, $q, $timeout, $log) {

View File

@ -33,16 +33,21 @@ define(
* @memberof platform/telemetry * @memberof platform/telemetry
*/ */
function TelemetryDelegator($q) { function TelemetryDelegator($q) {
return { this.$q = $q;
}
/** /**
* Promise telemetry-providing objects associated with * Promise telemetry-providing objects associated with
* this domain object (either the domain object itself, * this domain object (either the domain object itself,
* or the objects it delegates) * or the objects it delegates)
* @param {DomainObject} the domain object which may have
* or delegate telemetry
* @returns {Promise.<DomainObject[]>} domain objects with * @returns {Promise.<DomainObject[]>} domain objects with
* a telemetry capability * a telemetry capability
* @memberof platform/telemetry.TelemetryDelegator#
*/ */
promiseTelemetryObjects: function (domainObject) { TelemetryDelegator.prototype.promiseTelemetryObjects = function (domainObject) {
var $q = this.$q;
// If object has been cleared, there are no relevant // If object has been cleared, there are no relevant
// telemetry-providing domain objects. // telemetry-providing domain objects.
if (!domainObject) { if (!domainObject) {
@ -60,9 +65,7 @@ define(
tail = result || []; tail = result || [];
return head.concat(tail); return head.concat(tail);
}); });
}
}; };
}
return TelemetryDelegator; return TelemetryDelegator;
} }

View File

@ -39,15 +39,8 @@ define(
* @constructor * @constructor
*/ */
function TelemetryFormatter() { function TelemetryFormatter() {
function formatDomainValue(v, key) {
return isNaN(v) ? "" : moment.utc(v).format(DATE_FORMAT);
} }
function formatRangeValue(v, key) {
return isNaN(v) ? v : v.toFixed(3);
}
return {
/** /**
* Format a domain value. * Format a domain value.
* @param {number} v the domain value; a timestamp * @param {number} v the domain value; a timestamp
@ -57,9 +50,11 @@ define(
* be treated as a standard timestamp. * be treated as a standard timestamp.
* @returns {string} a textual representation of the * @returns {string} a textual representation of the
* data and time, suitable for display. * data and time, suitable for display.
* @memberof platform/telemetry.TelemetryFormatter#
*/ */
formatDomainValue: formatDomainValue, TelemetryFormatter.prototype.formatDomainValue = function (v, key) {
return isNaN(v) ? "" : moment.utc(v).format(DATE_FORMAT);
};
/** /**
* Format a range value. * Format a range value.
* @param {number} v the range value; a numeric value * @param {number} v the range value; a numeric value
@ -68,11 +63,10 @@ define(
* be treated as a numeric value. * be treated as a numeric value.
* @returns {string} a textual representation of the * @returns {string} a textual representation of the
* value, suitable for display. * value, suitable for display.
* @memberof platform/telemetry.TelemetryFormatter#
*/ */
formatRangeValue: formatRangeValue TelemetryFormatter.prototype.formatRangeValue = function (v, key) {
return isNaN(v) ? String(v) : v.toFixed(VALUE_FORMAT_DIGITS);
}; };
}
return TelemetryFormatter; return TelemetryFormatter;
} }

View File

@ -36,18 +36,30 @@ define(
* @param $q Angular's $q * @param $q Angular's $q
*/ */
function TelemetryHandler($q, telemetrySubscriber) { function TelemetryHandler($q, telemetrySubscriber) {
return { this.$q = $q;
handle: function (domainObject, callback, lossless) { this.telemetrySubscriber = telemetrySubscriber;
var subscription = telemetrySubscriber.subscribe( }
/**
* Start receiving telemetry associated with this domain object
* (either directly, or via delegation.)
* @param {DomainObject} domainObject the domain object
* @param {Function} callback callback to invoke when new data is
* available
* @param {boolean} lossless true if the callback should be invoked
* one separate time for each new latest value
* @returns {TelemetryHandle} a handle to telemetry data
* associated with this object
*/
TelemetryHandler.prototype.handle = function (domainObject, callback, lossless) {
var subscription = this.telemetrySubscriber.subscribe(
domainObject, domainObject,
callback, callback,
lossless lossless
); );
return new TelemetryHandle($q, subscription); return new TelemetryHandle(this.$q, subscription);
}
}; };
}
return TelemetryHandler; return TelemetryHandler;

View File

@ -34,6 +34,7 @@ define(
* objects.) * objects.)
* @memberof platform/telemetry * @memberof platform/telemetry
* @constructor * @constructor
* @implements {platform/telemetry.TelemetryPool}
*/ */
function TelemetryQueue() { function TelemetryQueue() {
// General approach here: // General approach here:
@ -61,8 +62,36 @@ define(
// a * * * * * // a * * * * *
// b * * * // b * * *
// c * * * // c * * *
var queue = [],
counts = {}; this.queue = [];
this.counts = {};
}
TelemetryQueue.prototype.isEmpty = function () {
return this.queue.length < 1;
};
TelemetryQueue.prototype.poll = function () {
var counts = this.counts;
// Decrement counts for a specific key
function decrementCount(key) {
if (counts[key] < 2) {
delete counts[key];
} else {
counts[key] -= 1;
}
}
// Decrement counts for the object that will be popped
Object.keys(counts).forEach(decrementCount);
return this.queue.shift();
};
TelemetryQueue.prototype.put = function (key, value) {
var queue = this.queue,
counts = this.counts;
// Look up an object in the queue that does not have a value // Look up an object in the queue that does not have a value
// assigned to this key (or, add a new one) // assigned to this key (or, add a new one)
@ -85,53 +114,8 @@ define(
return object; return object;
} }
// Decrement counts for a specific key
function decrementCount(key) {
if (counts[key] < 2) {
delete counts[key];
} else {
counts[key] -= 1;
}
}
// Decrement all counts
function decrementCounts() {
Object.keys(counts).forEach(decrementCount);
}
return {
/**
* Check if any value groups remain in this pool.
* @return {boolean} true if value groups remain
* @memberof platform/telemetry.TelemetryQueue#
*/
isEmpty: function () {
return queue.length < 1;
},
/**
* Retrieve the next value group from this pool.
* This gives an object containing key-value pairs,
* where keys and values correspond to the arguments
* given to previous put functions.
* @return {object} key-value pairs
* @memberof platform/telemetry.TelemetryQueue#
*/
poll: function () {
// Decrement counts for the object that will be popped
decrementCounts();
return queue.shift();
},
/**
* Put a key-value pair into the pool.
* @param {string} key the key to store the value under
* @param {*} value the value to store
* @memberof platform/telemetry.TelemetryQueue#
*/
put: function (key, value) {
getFreeObject(key)[key] = value; getFreeObject(key)[key] = value;
}
}; };
}
return TelemetryQueue; return TelemetryQueue;
} }

View File

@ -44,7 +44,10 @@ define(
* @param $timeout Angular's $timeout * @param $timeout Angular's $timeout
*/ */
function TelemetrySubscriber($q, $timeout) { function TelemetrySubscriber($q, $timeout) {
return { this.$q = $q;
this.$timeout = $timeout;
}
/** /**
* Subscribe to streaming telemetry updates * Subscribe to streaming telemetry updates
* associated with this domain object (either * associated with this domain object (either
@ -58,24 +61,18 @@ define(
* callback should be notified for all values * callback should be notified for all values
* (otherwise, multiple values in quick succession * (otherwise, multiple values in quick succession
* will call back with only the latest value.) * will call back with only the latest value.)
* @returns {TelemetrySubscription} the subscription, * @returns {platform/telemetry.TelemetrySubscription} the
* which will provide access to latest values. * subscription, which will provide access to latest values.
*
* @method
* @memberof TelemetrySubscriber
* @memberof platform/telemetry.TelemetrySubscriber#
*/ */
subscribe: function (domainObject, callback, lossless) { TelemetrySubscriber.prototype.subscribe = function (domainObject, callback, lossless) {
return new TelemetrySubscription( return new TelemetrySubscription(
$q, this.$q,
$timeout, this.$timeout,
domainObject, domainObject,
callback, callback,
lossless lossless
); );
}
}; };
}
return TelemetrySubscriber; return TelemetrySubscriber;
} }

View File

@ -26,6 +26,32 @@ define(
function (TelemetryQueue, TelemetryTable, TelemetryDelegator) { function (TelemetryQueue, TelemetryTable, TelemetryDelegator) {
"use strict"; "use strict";
/**
* A pool of telemetry values.
* @interface platform/telemetry.TelemetryPool
* @private
*/
/**
* Check if any value groups remain in this pool.
* @return {boolean} true if value groups remain
* @method platform/telemetry.TelemetryPool#isEmpty
*/
/**
* Retrieve the next value group from this pool.
* This gives an object containing key-value pairs,
* where keys and values correspond to the arguments
* given to previous put functions.
* @return {object} key-value pairs
* @method platform/telemetry.TelemetryPool#poll
*/
/**
* Put a key-value pair into the pool.
* @param {string} key the key to store the value under
* @param {*} value the value to store
* @method platform/telemetry.TelemetryPool#put
*/
/** /**
* A TelemetrySubscription tracks latest values for streaming * A TelemetrySubscription tracks latest values for streaming
* telemetry data and handles notifying interested observers. * telemetry data and handles notifying interested observers.
@ -52,14 +78,9 @@ define(
* the callback once, with access to the latest data * the callback once, with access to the latest data
*/ */
function TelemetrySubscription($q, $timeout, domainObject, callback, lossless) { function TelemetrySubscription($q, $timeout, domainObject, callback, lossless) {
var delegator = new TelemetryDelegator($q), var self = this,
unsubscribePromise, delegator = new TelemetryDelegator($q),
telemetryObjectPromise,
latestValues = {},
telemetryObjects = [],
pool = lossless ? new TelemetryQueue() : new TelemetryTable(), pool = lossless ? new TelemetryQueue() : new TelemetryTable(),
metadatas,
unlistenToMutation,
updatePending; updatePending;
// Look up domain objects which have telemetry capabilities. // Look up domain objects which have telemetry capabilities.
@ -72,7 +93,7 @@ define(
function updateValuesFromPool() { function updateValuesFromPool() {
var values = pool.poll(); var values = pool.poll();
Object.keys(values).forEach(function (k) { Object.keys(values).forEach(function (k) {
latestValues[k] = values[k]; self.latestValues[k] = values[k];
}); });
} }
@ -165,8 +186,8 @@ define(
// initial subscription chain; this allows `getTelemetryObjects()` // initial subscription chain; this allows `getTelemetryObjects()`
// to return a non-Promise to simplify usage elsewhere. // to return a non-Promise to simplify usage elsewhere.
function cacheObjectReferences(objects) { function cacheObjectReferences(objects) {
telemetryObjects = objects; self.telemetryObjects = objects;
metadatas = objects.map(lookupMetadata); self.metadatas = objects.map(lookupMetadata);
// Fire callback, as this will be the first time that // Fire callback, as this will be the first time that
// telemetry objects are available, or these objects // telemetry objects are available, or these objects
// will have changed. // will have changed.
@ -176,14 +197,6 @@ define(
return objects; return objects;
} }
function unsubscribeAll() {
return unsubscribePromise.then(function (unsubscribes) {
return $q.all(unsubscribes.map(function (unsubscribe) {
return unsubscribe();
}));
});
}
function initialize() { function initialize() {
// Get a reference to relevant objects (those with telemetry // Get a reference to relevant objects (those with telemetry
// capabilities) and subscribe to their telemetry updates. // capabilities) and subscribe to their telemetry updates.
@ -191,23 +204,23 @@ define(
// will be unsubscribe functions. (This must be a promise // will be unsubscribe functions. (This must be a promise
// because delegation is supported, and retrieving delegate // because delegation is supported, and retrieving delegate
// telemetry-capable objects may be an asynchronous operation.) // telemetry-capable objects may be an asynchronous operation.)
telemetryObjectPromise = promiseRelevantObjects(domainObject); self.telemetryObjectPromise = promiseRelevantObjects(domainObject);
unsubscribePromise = telemetryObjectPromise self.unsubscribePromise = self.telemetryObjectPromise
.then(cacheObjectReferences) .then(cacheObjectReferences)
.then(subscribeAll); .then(subscribeAll);
} }
function idsMatch(ids) { function idsMatch(ids) {
return ids.length === telemetryObjects.length && return ids.length === self.telemetryObjects.length &&
ids.every(function (id, index) { ids.every(function (id, index) {
return telemetryObjects[index].getId() === id; return self.telemetryObjects[index].getId() === id;
}); });
} }
function modelChange(model) { function modelChange(model) {
if (!idsMatch((model || {}).composition || [])) { if (!idsMatch((model || {}).composition || [])) {
// Reinitialize if composition has changed // Reinitialize if composition has changed
unsubscribeAll().then(initialize); self.unsubscribeAll().then(initialize);
} }
} }
@ -219,23 +232,35 @@ define(
} }
} }
initialize(); this.$q = $q;
unlistenToMutation = addMutationListener(); this.latestValues = {};
this.telemetryObjects = [];
this.metadatas = [];
initialize();
this.unlistenToMutation = addMutationListener();
}
TelemetrySubscription.prototype.unsubscribeAll = function () {
var $q = this.$q;
return this.unsubscribePromise.then(function (unsubscribes) {
return $q.all(unsubscribes.map(function (unsubscribe) {
return unsubscribe();
}));
});
};
return {
/** /**
* Terminate all underlying subscriptions associated * Terminate all underlying subscriptions associated
* with this object. * with this object.
* @method
* @memberof TelemetrySubscription
* @memberof platform/telemetry.TelemetrySubscription#
*/ */
unsubscribe: function () { TelemetrySubscription.prototype.unsubscribe = function () {
if (unlistenToMutation) { if (this.unlistenToMutation) {
unlistenToMutation(); this.unlistenToMutation();
} }
return unsubscribeAll(); return this.unsubscribeAll();
}, };
/** /**
* Get the most recent domain value that has been observed * Get the most recent domain value that has been observed
* for the specified domain object. This will typically be * for the specified domain object. This will typically be
@ -247,14 +272,12 @@ define(
* *
* @param {DomainObject} domainObject the object of interest * @param {DomainObject} domainObject the object of interest
* @returns the most recent domain value observed * @returns the most recent domain value observed
* @method
* @memberof TelemetrySubscription
* @memberof platform/telemetry.TelemetrySubscription#
*/ */
getDomainValue: function (domainObject) { TelemetrySubscription.prototype.getDomainValue = function (domainObject) {
var id = domainObject.getId(); var id = domainObject.getId();
return (latestValues[id] || {}).domain; return (this.latestValues[id] || {}).domain;
}, };
/** /**
* Get the most recent range value that has been observed * Get the most recent range value that has been observed
* for the specified domain object. This will typically * for the specified domain object. This will typically
@ -266,25 +289,23 @@ define(
* *
* @param {DomainObject} domainObject the object of interest * @param {DomainObject} domainObject the object of interest
* @returns the most recent range value observed * @returns the most recent range value observed
* @method
* @memberof TelemetrySubscription
* @memberof platform/telemetry.TelemetrySubscription#
*/ */
getRangeValue: function (domainObject) { TelemetrySubscription.prototype.getRangeValue = function (domainObject) {
var id = domainObject.getId(); var id = domainObject.getId();
return (latestValues[id] || {}).range; return (this.latestValues[id] || {}).range;
}, };
/** /**
* Get the latest telemetry datum for this domain object. * Get the latest telemetry datum for this domain object.
* *
* @param {DomainObject} domainObject the object of interest * @param {DomainObject} domainObject the object of interest
* @returns {TelemetryDatum} the most recent datum * @returns {TelemetryDatum} the most recent datum
* @memberof platform/telemetry.TelemetrySubscription#
*/ */
getDatum: function (domainObject) { TelemetrySubscription.prototype.getDatum = function (domainObject) {
var id = domainObject.getId(); var id = domainObject.getId();
return (latestValues[id] || {}).datum; return (this.latestValues[id] || {}).datum;
}, };
/** /**
* Get all telemetry-providing domain objects which are * Get all telemetry-providing domain objects which are
* being observed as part of this subscription. * being observed as part of this subscription.
@ -297,13 +318,11 @@ define(
* return an empty array. * return an empty array.
* *
* @returns {DomainObject[]} all subscribed-to domain objects * @returns {DomainObject[]} all subscribed-to domain objects
* @method
* @memberof TelemetrySubscription
* @memberof platform/telemetry.TelemetrySubscription#
*/ */
getTelemetryObjects: function () { TelemetrySubscription.prototype.getTelemetryObjects = function () {
return telemetryObjects; return this.telemetryObjects;
}, };
/** /**
* Get all telemetry metadata associated with * Get all telemetry metadata associated with
* telemetry-providing domain objects managed by * telemetry-providing domain objects managed by
@ -314,12 +333,12 @@ define(
* `getResponse()`; that is, the metadata at a * `getResponse()`; that is, the metadata at a
* given index will correspond to the telemetry-providing * given index will correspond to the telemetry-providing
* domain object at the same index. * domain object at the same index.
* @returns {Array} an array of metadata objects * @returns {TelemetryMetadata[]} an array of metadata objects
* @memberof platform/telemetry.TelemetrySubscription#
*/ */
getMetadata: function () { TelemetrySubscription.prototype.getMetadata = function () {
return metadatas; return this.metadatas;
}, };
/** /**
* Get a promise for all telemetry-providing objects * Get a promise for all telemetry-providing objects
* associated with this subscription. * associated with this subscription.
@ -327,13 +346,11 @@ define(
* telemetry-providing objects * telemetry-providing objects
* @memberof platform/telemetry.TelemetrySubscription# * @memberof platform/telemetry.TelemetrySubscription#
*/ */
promiseTelemetryObjects: function () { TelemetrySubscription.prototype.promiseTelemetryObjects = function () {
// Unsubscribe promise is available after objects // Unsubscribe promise is available after objects
// are loaded. // are loaded.
return telemetryObjectPromise; return this.telemetryObjectPromise;
}
}; };
}
return TelemetrySubscription; return TelemetrySubscription;

View File

@ -34,44 +34,25 @@ define(
* values. * values.
* @memberof platform/telemetry * @memberof platform/telemetry
* @constructor * @constructor
* @implements {platform/telemetry.TelemetryPool}
*/ */
function TelemetryTable() { function TelemetryTable() {
var table; }
return { TelemetryTable.prototype.isEmpty = function () {
/** return !this.table;
* Check if any value groups remain in this pool. };
* @return {boolean} true if value groups remain
* @memberof platform/telemetry.TelemetryTable# TelemetryTable.prototype.poll = function () {
*/ var t = this.table;
isEmpty: function () { this.table = undefined;
return !table; return t;
}, };
/**
* Retrieve the next value group from this pool. TelemetryTable.prototype.put = function (key, value) {
* This gives an object containing key-value pairs, this.table = this.table || {};
* where keys and values correspond to the arguments this.table[key] = value;
* given to previous put functions.
* @return {object} key-value pairs
* @memberof platform/telemetry.TelemetryTable#
*/
poll: function () {
var t = table;
table = undefined;
return t;
},
/**
* Put a key-value pair into the pool.
* @param {string} key the key to store the value under
* @param {*} value the value to store
* @memberof platform/telemetry.TelemetryTable#
*/
put: function (key, value) {
table = table || {};
table[key] = value;
}
}; };
}
return TelemetryTable; return TelemetryTable;
} }