I agree “thread of execution” is probably not the most accurate 
description, I guess what I meant is more “the current stack of execution”. 

Any angular user code will be triggered by some browser event, and the 
event handler is responsible of wrapping any further calls inside a 
$scope.$apply(). Therefore developers should expect that $digest will be 
called once whatever triggered the execution of their code is done 
executing.

The reason I said I questioned the usefulness is that having the developer 
be aware of specific timing or triggers for a $digest confuses things more 
than it help. A more useful and practical list, in my opinion, is when 
$digest is *NOT* called, which is simply when you are writing your own 
event handler (in which you should be calling $apply() manually. 

I just see too many developers get confused by these things and try to 
micro-manage digest cycles and liter their code with $apply() everywhere.

On Sunday, February 16, 2014 11:41:58 AM UTC-8, Mark Volkmann wrote:

My motivation for enumerating these is to finally understand what is 
> happening beneath the covers. I understand that any code could call $apply 
> or $digest on the scope for other circumstances. I think it's really useful 
> when explaining to others how dirty checking works in Angular to be able to 
> provide common examples of what can trigger it.
>
> Since JavaScript doesn't use threads, I assume when you say "thread of 
> execution" you are referring to the event queue.
>
>
> On Sun, Feb 16, 2014 at 12:29 PM, Daniel Tabuenca 
> <dtab...@gmail.com<javascript:>
> > wrote:
>
>> Your list is fine, but I question the usefulness of compiling an 
>> exhaustive list of every time that $digest is called, especially since 
>> third-party directives could add additional services and callbacks which 
>> would add to your list.  Quite simply, in a properly written application 
>> $digest will be called at the end of any thread of execution, regardless of 
>> how it is started. What you are enumerating then, is simply ways that 
>> threads of execution can be started, and most of those just boil down to 
>> "when an asynchronous callback gets executed".  May I ask what your 
>> motivation is for compiling this list?
>>
>>
>>
>>
>> On Sunday, February 16, 2014 9:49:04 AM UTC-8, Mark Volkmann wrote:
>>>
>>> I couldn't find a concise list of the things that trigger a digest cycle 
>>> to run.
>>> After some investigation, I came up with the following list.
>>> Does this look correct? What did I miss?
>>>
>>> - bootstrap process
>>> - user input triggers a provided event handing directive; ex. *ng-click*
>>> - change to an *ng-model* property caused by user input or code
>>> - after *$http* promises are resolved or rejected
>>> - after *$timeout* and *$interval* listeners run
>>> - after a route change
>>> - calls to *scope.**$apply*
>>>
>>> -- 
>>> R. Mark Volkmann
>>> Object Computing, Inc. 
>>>
>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "AngularJS" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to angular+u...@googlegroups.com <javascript:>.
>> To post to this group, send email to ang...@googlegroups.com<javascript:>
>> .
>> Visit this group at http://groups.google.com/group/angular.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>
>
> -- 
> R. Mark Volkmann
> Object Computing, Inc. 
>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to angular+unsubscr...@googlegroups.com.
To post to this group, send email to angular@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to