Angular: $eval & $timeout

Source: Internet
Author: User

$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 &&current.$ $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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.