3 ms·
The implementation of overriding the scope's $watch method is fairly straight forward. We gave our optimization directive a fairly high priority so that it was
by sczerwin 13y ago
The implementation of overriding the scope's $watch method is fairly straight forward.
We gave our optimization directive a fairly high priority so that it was guaranteed to be run first (among all the other directives on an element).
When the optimization directive ran, it just modified the scope variable passed to it, saving a reference to the original scope.$watch method and then setting scope.$watch to a new function we created. Inside that function, it does invoke the original scope.$watch.
We also had to override scope.$new to guarantee that any child elements, if they create new scopes, also create scopes with our override $watch method.
- ganarajpr 13y agoI am not sure if this will be of any help. But you could actually globally override $watch - without it feeling like a hack. Angular does provide a mechanism to do that. Since $rootScope is a service, you can have a decorator for it where you can override the $watch which will override the $watch for all scopes. Angular Batarang overrides $watch too for instrumentation. Consider this one more request for publishing your directives and changes :)