A
A
Alexander2015-10-25 17:25:41
Angular
Alexander, 2015-10-25 17:25:41

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

1 answer(s)
L
lega, 2015-10-25
@s2nner

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).
Also now in all frameworks there is a trend towards (isolated) components, therefore, with the correct construction of a web application (1000 components x 1000 watches) -> and 1M watches will work quickly (1ms).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question