[Telemetry] Unsubscribe on composition change

WTD-1329.
This commit is contained in:
Victor Woeltjen
2015-06-24 12:27:20 -07:00
parent 7a531493d8
commit f98344b5f6

View File

@ -154,6 +154,14 @@ 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.
@ -176,7 +184,7 @@ define(
function modelChange(model) { function modelChange(model) {
if (!idsMatch((model || {}).composition || [])) { if (!idsMatch((model || {}).composition || [])) {
// Reinitialize if composition has changed // Reinitialize if composition has changed
initialize(); unsubscribeAll().then(initialize);
} }
} }
@ -201,11 +209,7 @@ define(
if (unlistenToMutation) { if (unlistenToMutation) {
unlistenToMutation(); unlistenToMutation();
} }
return unsubscribePromise.then(function (unsubscribes) { return unsubscribeAll();
return $q.all(unsubscribes.map(function (unsubscribe) {
return unsubscribe();
}));
});
}, },
/** /**
* Get the most recent domain value that has been observed * Get the most recent domain value that has been observed