Merge remote-tracking branch 'origin/open840' into open-master

This commit is contained in:
bwyu 2015-02-11 13:19:07 -08:00
commit 471e86bd6d
2 changed files with 25 additions and 0 deletions

View File

@ -113,8 +113,20 @@ define(
}
}
// Release the current subscription (called when scope is destroyed)
function releaseSubscription() {
if (subscription) {
subscription.unsubscribe();
subscription = undefined;
}
}
// Subscribe to telemetry when a domain object becomes available
$scope.$watch('domainObject', subscribe);
// Unsubscribe when the plot is destroyed
$scope.$on("$destroy", releaseSubscription);
return {
/**
* Get the color (as a style-friendly string) to use

View File

@ -173,6 +173,19 @@ define(
// Placeholder; need to support requesting telemetry
expect(controller.isRequestPending()).toBeFalsy();
});
it("unsubscribes when destroyed", function () {
// Make an object available
mockScope.$watch.mostRecentCall.args[1](mockDomainObject);
// Make sure $destroy is what's listened for
expect(mockScope.$on.mostRecentCall.args[0]).toEqual('$destroy');
// Also verify precondition
expect(mockSubscription.unsubscribe).not.toHaveBeenCalled();
// Destroy the scope
mockScope.$on.mostRecentCall.args[1]();
// Should have unsubscribed
expect(mockSubscription.unsubscribe).toHaveBeenCalled();
});
});
}
);