$digest:function() { varWatch, value, last, watchers, Length, dirty, TTL=TTL, Next, current, target= This, Watchlog=[], Logidx, logmsg, Asynctask; Beginphase (' $digest '); //Check for changes to browser URL, happened in sync before the call to $digest$browser. $ $checkUrlChange (); if( This= = = $rootScope && applyasyncid!==NULL) { //If This is the root scope, and $applyAsync have scheduled a deferred $apply (), then //Cancel the scheduled $apply and flush the queue of expressions to be evaluated.$browser. Defer.cancel (APPLYASYNCID); Flushapplyasync (); } Lastdirtywatch=NULL; Do{//"While dirty" loopDirty =false; Current=Target; while(asyncqueue.length) { //Run first $eval Try{Asynctask=Asyncqueue.shift (); Asynctask.scope. $eval (Asynctask.expression, asynctask.locals); } Catch(e) {$exceptionHandler (e); } Lastdirtywatch=NULL; } Traversescopesloop: Do{//"traverse the scopes" loop if((Watchers =current.$ $watchers)) { //Process Our watchesLength =watchers.length; while(length--) { Try{Watch=Watchers[length]; //Most common watches is on primitives, in which case we can short //circuit it with = = = operator, only when = = = = Fails do we use. Equals if(watch) {if(value = Watch.get (current))!== (last = watch.last) &&!(Watch.eq?equals (value, last): (typeofValue = = ' Number ' &&typeoflast = = = ' Number ' && IsNaN (value) &&IsNaN (last)))) {Dirty=true; Lastdirtywatch=Watch; Watch.last= Watch.eq? Copy (value,NULL): value; Watch.fn (Value, (last= = = Initwatchval)?value:last), current); if(TTL < 5) {Logidx= 4-TTL; if(!watchlog[logidx]) watchlog[logidx] = []; Watchlog[logidx].push ({msg:isfunction (watch.exp)? ' fn: ' + (Watch.exp.name | |watch.exp.toString ()): Watch.exp, Newval:value, Oldval:last }); } } Else if(Watch = = =Lastdirtywatch) { //If The most recently dirty watcher are now clean, short circuit since the remaining watchers //There are already been tested.Dirty =false; BreakTraversescopesloop; } } } Catch(e) {$exceptionHandler (e); } } } //Insanity Warning:scope Depth-first traversal //Yes, this code was a bit crazy, but it works and we had tests to prove it! //This piece should is kept in sync with the traversal in $broadcast if(! (Next = ((current.$ $watchersCount && current.$ $childHead) | |( current!== Target &¤t.$ $nextSibling)))) { while(Current!== target &&!) (Next =current.$ $nextSibling)) { Current=Current . $parent; } } } while(current =next)); //' break traversescopesloop; ' takes us -here if((Dirty | | asyncqueue.length) &&! (ttl--) ) {clearphase (); Throw$ROOTSCOPEMINERR (' Infdig ', ' {0} $digest () iterations reached. aborting!\n ' + ' watchers fired in the last 5 iterations: {1} ', TTL, Watchlog); } } while(Dirty | |asyncqueue.length); Clearphase (); while(postdigestqueue.length) {//Last run $timeout Try{postdigestqueue.shift () (); } Catch(e) {$exceptionHandler (e); } } },
Angular Digest will run $browser first. $ $checkUrlChange (); the others I took, followed by check dirty and asyncqueue.length. And finally, check postdigestquese.length.
Angular: $eval & $timeout