[Telemetry] Fix failing specs

Fix failing specs related to usage of subscriptions in the
TelemetryController, introduced for WTD-644.
This commit is contained in:
Victor Woeltjen
2015-01-12 08:43:29 -08:00
parent de57628b01
commit 12c4863feb
2 changed files with 28 additions and 24 deletions

View File

@ -123,6 +123,21 @@ define(
}));
}
// Subscribe to streaming telemetry updates
function subscribe(telemetryCapability, id) {
return telemetryCapability.subscribe(function () {
requestTelemetryForId(id, false);
});
}
// Stop listening to active subscriptions
function unsubscribe() {
self.subscriptions.forEach(function (s) {
return s && s();
});
self.subscriptions = [];
}
// Look up domain objects which have telemetry capabilities.
// This will either be the object in view, or object that
// this object delegates its telemetry capability to.
@ -152,12 +167,17 @@ define(
function buildResponseContainer(domainObject) {
var telemetry = domainObject &&
domainObject.getCapability("telemetry"),
id,
metadata;
if (telemetry) {
id = domainObject.getId();
self.subscriptions.push(subscribe(telemetry, id));
metadata = telemetry.getMetadata();
self.response[domainObject.getId()] = {
self.response[id] = {
name: domainObject.getModel().name,
domainObject: domainObject,
metadata: metadata,
@ -186,29 +206,13 @@ define(
}
}
// Subscribe to streaming telemetry updates
function subscribe(domainObject) {
var telemetryCapability =
domainObject.getCapability("telemetry");
return telemetryCapability.subscribe(function () {
requestTelemetryForId(
domainObject.getId(),
false
);
});
}
// Stop listening to active subscriptions
function unsubscribe() {
self.subscriptions.forEach(function (s) {
return s && s();
});
}
// Build response containers (as above) for all
// domain objects, and update some controller-internal
// state to support subsequent calls.
function buildResponseContainers(domainObjects) {
// Clear out any existing subscriptions
unsubscribe();
// Build the containers
domainObjects.forEach(buildResponseContainer);
@ -227,9 +231,6 @@ define(
return self.response[id].metadata;
});
// Subscribe to all telemetry objects
self.subscriptions = domainObjects.map(subscribe);
// Issue a request for the new objects, if we
// know what our request looks like
if (self.request) {