problem description
In Vue, if wather is not updated by Synchronize, it will be put in a queue and will be updated after the end of the same event loop. The relevant code is in the queueWatcher method of scheduler.
this deals with a scenario:
wather is triggered when the queue is being updated.
if (!flushing) {
queue.push(watcher)
} else {
let i = queue.length - 1
while (i > index && queue[i].id > watcher.id) {
i--
}
queue.splice(i + 1, 0, watcher)
}
}
I don"t understand why we have to deal with it this way. Can"t you push directly to the end?
what are the benefits of such a design now?
append description. The code
vue is not in the same time cycle. If the wather, is not executed and the wather is triggered again, it will only be executed once.
queue.splice(i + 1, 0, watcher)
this side knows the index, before this wather and issues the second touch behind this. Still execute update twice. Since they are all executed twice, why not push directly to the last