Joined March 2015
·

Eugenio

Argentina
·
·

Posted to Speeding up AngularJS's $digest loop over 1 year ago

What if...

.directive('faSuspendable', function () {
return {
link: function (scope) {
// Heads up: this might break is suspend/resume called out of order
// or if watchers are added while suspended
var watchers = [];
scope.$on('suspend', function () {
for (var i = 0, l = scope.$$watchers.length; i < l; i += 1){
watchers.push(scope.$$watchers[i]);
}
scope.$$watchers = [];
});

  scope.$on('resume', function () {
    while (watchers.length > 0) {
        scope.$$watchers.unshift(watchers.pop());
    }
  });
}

};
})

Achievements
1 Karma
0 Total ProTip Views