Skip to content

Commit c636a03

Browse files
committed
further tweak batching strategy
1 parent aca70e0 commit c636a03

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/batcher.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,17 @@ var userQueue = []
1717
var has = {}
1818
var circular = {}
1919
var waiting = false
20-
var internalQueueDepleted = false
2120

2221
/**
2322
* Reset the batcher's state.
2423
*/
2524

2625
function resetBatcherState () {
27-
queue = []
28-
userQueue = []
26+
queue.length = 0
27+
userQueue.length = 0
2928
has = {}
3029
circular = {}
31-
waiting = internalQueueDepleted = false
30+
waiting = false
3231
}
3332

3433
/**
@@ -37,8 +36,12 @@ function resetBatcherState () {
3736

3837
function flushBatcherQueue () {
3938
runBatcherQueue(queue)
40-
internalQueueDepleted = true
39+
queue.length = 0
4140
runBatcherQueue(userQueue)
41+
// user watchers triggered more internal watchers
42+
if (queue.length) {
43+
runBatcherQueue(queue)
44+
}
4245
// dev tool hook
4346
/* istanbul ignore if */
4447
if (devtools && config.devtools) {
@@ -88,13 +91,13 @@ function runBatcherQueue (queue) {
8891
*/
8992

9093
export function pushWatcher (watcher) {
91-
var id = watcher.id
94+
const id = watcher.id
9295
if (has[id] == null) {
9396
// push watcher into appropriate queue
94-
var q = internalQueueDepleted || watcher.user
97+
const q = watcher.user
9598
? userQueue
9699
: queue
97-
has[id] = true
100+
has[id] = q.length
98101
q.push(watcher)
99102
// queue the flush
100103
if (!waiting) {

0 commit comments

Comments
 (0)