Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple $watch can be a performance drag #6

Open
wjaspers opened this issue Dec 19, 2019 · 1 comment
Open

Multiple $watch can be a performance drag #6

wjaspers opened this issue Dec 19, 2019 · 1 comment

Comments

@wjaspers
Copy link

On the off-chance someone is using this more than once in the page, this adds more $watch functions than it needs. Only one is necessary, and only a single change detection can trigger the diff. Near simultaneous changes to left and right would otherwise create separate digest cycles.

Newer angular standards/preferences would suggest binding left and right to the controller, but for the sake of the current code, here's all that's needed.

var _this = this;
var unbindWatch = $scope.$watch(function () {
   return { left: $scope.left, right: $scope.right };
}, function (newValue, oldValue, localScope) {
  _this.doDiff();
}, true); 
$scope.$on("$destroy", unbindWatch);
@bill-long
Copy link
Owner

I'm not really maintaining this anymore. If you want to submit a PR, I'll merge it in, though it looks like the change above is only to the .js file? A change to the .ts would be preferred, and then the .js can just be compiled from it.

But I'd be happy for anyone actively using this to take over.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants