angular / angular-hint

run-time hinting for AngularJS applications
362 stars 45 forks source link

$watch override makes one-time bindings in expressions to never clear the associated watch #109

Closed raulmt closed 7 years ago

raulmt commented 9 years ago

This function wrapping done to measure the watchExpression call's performance (https://github.com/angular/angular-hint/blob/master/src/modules/scopes.js#L110-L120) makes one-time binding expressions and also literal string expressions to keep the watcher on scope and executing it forever.

I think the problem is the wrapping function doesn't inherit properties of the original function. One of the missing properties I think causes this wrong behaviour is $$watchDelegate which, in case of one-time bindings and literal string bindings functions has the logic to remove the watch after the first stable call.

The original $watch function checks wether watchExpression function has a $$watchDelegate and calls it if it does. And after adding this file (angular-hint), those wrapped watchExpression functions will never have a $$watchDelegate so the watch will not be removed.

I had this issue while using angular Batarang (Angular's Chrome extension). I noticed that while having Batarang active, adding :: to bracket expressions didn't make me lower the watchers count.

I'm using latest Batarang version (0.8.6) which includes angular-hint 0.3.4.

erwinmombay commented 9 years ago

thats true, that definitely is a problem. i'll take a look if theres anything we can do, feel free to add more comments/suggestions or send a PR if you think up of anything as well. appreciate you reporting this!

OACDesigns commented 7 years ago

just a bump on this, there's a small but important part missing in the isOneTimeBindExp that means {{ ::value }} doesn't get counted as a one-time binding, while {{::value}} does. I've submitted a PR to fix this: https://github.com/angular/angular-hint/pull/122