@@ -27,7 +27,7 @@ function reset () {
27
27
}
28
28
29
29
/**
30
- * Flush both queues and run the jobs .
30
+ * Flush both queues and run the watchers .
31
31
*/
32
32
33
33
function flush ( ) {
@@ -38,53 +38,58 @@ function flush () {
38
38
}
39
39
40
40
/**
41
- * Run the jobs in a single queue.
41
+ * Run the watchers in a single queue.
42
42
*
43
43
* @param {Array } queue
44
44
*/
45
45
46
46
function run ( queue ) {
47
- // do not cache length because more jobs might be pushed
48
- // as we run existing jobs
47
+ // do not cache length because more watchers might be pushed
48
+ // as we run existing watchers
49
49
for ( var i = 0 ; i < queue . length ; i ++ ) {
50
- var job = queue [ i ]
51
- var id = job . id
50
+ var watcher = queue [ i ]
51
+ var id = watcher . id
52
52
has [ id ] = null
53
- job . run ( )
53
+ watcher . run ( )
54
+ // in dev build, check and stop circular updates.
54
55
if ( process . env . NODE_ENV !== 'production' && has [ id ] != null ) {
55
56
circular [ id ] = ( circular [ id ] || 0 ) + 1
56
57
if ( circular [ id ] > config . _maxUpdateCount ) {
57
58
queue . splice ( has [ id ] , 1 )
58
59
_ . warn (
59
60
'You may have an infinite update loop for watcher ' +
60
- 'with expression: ' + job . expression
61
+ 'with expression: ' + watcher . expression
61
62
)
62
63
}
63
64
}
64
65
}
65
66
}
66
67
67
68
/**
68
- * Push a job into the job queue.
69
+ * Push a watcher into the watcher queue.
69
70
* Jobs with duplicate IDs will be skipped unless it's
70
71
* pushed when the queue is being flushed.
71
72
*
72
- * @param {Object } job
73
+ * @param {Watcher } watcher
73
74
* properties:
74
- * - {String| Number} id
75
- * - {Function} run
75
+ * - {Number} id
76
+ * - {Function} run
76
77
*/
77
78
78
- exports . push = function ( job ) {
79
- var id = job . id
79
+ exports . push = function ( watcher ) {
80
+ var id = watcher . id
80
81
if ( has [ id ] == null ) {
81
- if ( internalQueueDepleted && ! job . user ) {
82
- job . run ( )
82
+ // if an internal watcher is pushed, but the internal
83
+ // queue is already depleted, we run it immediately.
84
+ if ( internalQueueDepleted && ! watcher . user ) {
85
+ watcher . run ( )
83
86
return
84
87
}
85
- var q = job . user ? userQueue : queue
88
+ // push watcher into appropriate queue
89
+ var q = watcher . user ? userQueue : queue
86
90
has [ id ] = q . length
87
- q . push ( job )
91
+ q . push ( watcher )
92
+ // queue the flush
88
93
if ( ! waiting ) {
89
94
waiting = true
90
95
_ . nextTick ( flush )
0 commit comments