A long time did not write something, from today, in the blog Park on their past work, study and life to do some combing, summary and temperature. Today the sun outside the window is not so wayward, the sky Baiyun Point, cicada still loud and quiet, sitting quietly on the balcony, blowing wind, tapping the keyboard. In my case, this is a happy life.
To the point, the angularjs dirty check mechanism made a review and summarized as follows:
Reference article:
http://teropa.info/build-your-own-angular/
Http://www.cnblogs.com/likeFlyingFish/p/6183630.html
http://www.ituring.com.cn/article/39865
1, angular is not a periodic trigger dirty check, not a long connection polling check.
2, generally an event loop in the execution to the task queue, such as UI events, AJAX requests or timeout delay events, such as triggering dirty check.
3, Angular each data bound to the UI, there will be a $watch object.
4. All watch stored in the $watchList, a dirty check is called once $apply () or $digest (), traverse check all watch, the data in the latest values rendered on the interface.
5. $digest now run at least one listener at a time. If the monitoring value changes after the first run, all listeners are marked as dirty, and the listener runs a second time. This will run until all the monitored values are no longer changing and the whole situation is stabilized.
6, about $apply, the big idea is that we can execute some code unrelated to angular, which can also change the scope of things, $apply can ensure that the scope of the listener can detect these changes. When people talk about using $apply to integrate code into the "angular life cycle," they are referring to this thing, and nothing is more important than that.
7, but there is a way to delay code in angular, that is, the $evalasync function on the scope. $evalAsync accept a function that is scheduled to be executed in the current ongoing digest or before the next digest. For example, you can defer execution of some code in a listener's listener function, even if it has been delayed, and will still be executed in the existing digest traversal.
Angularjs Dirty Check mechanism