-
Notifications
You must be signed in to change notification settings - Fork 77
Closed
Labels
Description
We have a problem of numerous $rootScope.$digest calls that results of calling all watchers of all scopes.
This happens because we have several instances of color picker on the same page, each one of them adding an event handler for all clicks on the whole document:
$document.on('click', function (evt) {
if ($scope.find(evt.target).length === 0) {
$scope.log('Color Picker: Document Hide Event');
$scope.hide();
}
});
$scope.hide = function (apply) {
$scope.log('Color Picker: Hide Event');
$scope.visible = false;
if (apply !== false) {
$scope.$apply();
}
};What I see that could be improved:
- check if
$scope.visibleistrueand exit early otherwise, - rewrite
$scope.containsto use native contains method. Check for performance test - get rid of calling
$scope.$apply()? - handle
$destroyevent to remove click event listeners, - store references to all instances and call event handler only once?
Thank you.