Answer the question
In order to leave comments, you need to log in
How does Angular.JS work at the lowest level?
I read articles, googled, but it's still not entirely clear how real-time change tracking is implemented.
Here, for example , Make your own AngularJS , the author himself calls scope.$digest();
At the moment my guess is:
it's an infinite loop comparing 2 objects.
But then iterations on different machines work at different speeds.
And if there are a lot of ng directives, is it very expensive?
Answer the question
In order to leave comments, you need to log in
In fact, everything is correct in the article, this is not an infinite loop, but the old and current values \u200b\u200bare compared in it, in case of a difference, "callbacks" are called.
$digest() is called on every corner and on every sneeze: after $timout, after $http, after ng-click, etc., therefore, the illusion of "real-time change tracking" is created.
And if there are a lot of ng directives, is it very expensive?On modern hardware and browser, more than 10M comparisons per second can occur, so applications with a small $digest with a small number of 1000-20k watches are fast (depending on the watches).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question