Skip to content
This repository was archived by the owner on Oct 22, 2021. It is now read-only.
This repository was archived by the owner on Oct 22, 2021. It is now read-only.

watching undefined variable causes many "fake" watchers to be created #36

@yonihei

Description

@yonihei

In short: using the plugin on an undefined object causes the number of watchers to grow for no reason constantly.

ng-if=":auto:d.fakeVariable"

http://jsbin.com/titozudubo/edit?html,js,output
(i hope it is working, but ill write here anyway the problem)

Explanation:
i use a short code for finding the number watchers. i hope its is not buggy. Each time that the key "auto" has changed, it creates more watchers for no reason because d.fakeVariable is not defined.

here is the code for counting the number of watchers:

var getWatchers = function(root) {
root = angular.element(root || document.documentElement);
var watcherCount = 0;

  var getElemWatchers = function(element) {
    var isolateWatchers = getWatchersFromScope(element.data().$isolateScope);
    var scopeWatchers = getWatchersFromScope(element.data().$scope);
    var watchers = scopeWatchers.concat(isolateWatchers);
    angular.forEach(element.children(), function (childElement) {
      watchers = watchers.concat(getElemWatchers(angular.element(childElement)));
    });
    return watchers;
  }
  
  var getWatchersFromScope = function(scope) {
    if (scope) {
      return scope.$$watchers || [];
    } else {
      return [];
    }
  }
 
  return getElemWatchers(root);
};

console.log(getWatchers ().length);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions