|
|
@@ -1,4 +1,5 @@
|
|
|
var _ = require('./util')
|
|
|
+var MAX_UPDATE_COUNT = 10
|
|
|
|
|
|
// we have two separate queues: one for directive updates
|
|
|
// and one for user watcher registered via $watch().
|
|
|
@@ -61,7 +62,21 @@ function run (queue) {
|
|
|
*/
|
|
|
|
|
|
exports.push = function (job) {
|
|
|
- if (!job.id || !has[job.id] || flushing) {
|
|
|
+ var id = job.id
|
|
|
+ if (!id || !has[id] || flushing) {
|
|
|
+ if (!has[id]) {
|
|
|
+ has[id] = 1
|
|
|
+ } else {
|
|
|
+ has[id]++
|
|
|
+ // detect possible infinite update loops
|
|
|
+ if (has[id] > MAX_UPDATE_COUNT) {
|
|
|
+ _.warn(
|
|
|
+ 'You may have an infinite update loop for the ' +
|
|
|
+ 'watcher with expression: "' + job.expression + '".'
|
|
|
+ )
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
// A user watcher callback could trigger another
|
|
|
// directive update during the flushing; at that time
|
|
|
// the directive queue would already have been run, so
|
|
|
@@ -71,7 +86,6 @@ exports.push = function (job) {
|
|
|
return
|
|
|
}
|
|
|
;(job.user ? userQueue : queue).push(job)
|
|
|
- has[job.id] = job
|
|
|
if (!waiting) {
|
|
|
waiting = true
|
|
|
_.nextTick(flush)
|