Skip to content

$rootScope.$digest overwhelming calls #30

@FarSeeing

Description

@FarSeeing

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.visible is true and exit early otherwise,
  • rewrite $scope.contains to use native contains method. Check for performance test
  • get rid of calling $scope.$apply()?
  • handle $destroy event to remove click event listeners,
  • store references to all instances and call event handler only once?

Thank you.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions