|
|
@@ -36,12 +36,25 @@ function resetBatcherState () {
|
|
|
*/
|
|
|
|
|
|
function flushBatcherQueue () {
|
|
|
+ queue.sort(queueSorter)
|
|
|
runBatcherQueue(queue)
|
|
|
internalQueueDepleted = true
|
|
|
runBatcherQueue(userQueue)
|
|
|
resetBatcherState()
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Sort queue before flush.
|
|
|
+ * This ensures components are updated from parent to child
|
|
|
+ * so there will be no duplicate updates, e.g. a child was
|
|
|
+ * pushed into the queue first and then its parent's props
|
|
|
+ * changed.
|
|
|
+ */
|
|
|
+
|
|
|
+function queueSorter (a, b) {
|
|
|
+ return a.id - b.id
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* Run the watchers in a single queue.
|
|
|
*
|
|
|
@@ -55,6 +68,7 @@ function runBatcherQueue (queue) {
|
|
|
var watcher = queue[queueIndex]
|
|
|
var id = watcher.id
|
|
|
has[id] = null
|
|
|
+ console.log('running: ' + id)
|
|
|
watcher.run()
|
|
|
// in dev build, check and stop circular updates.
|
|
|
if (process.env.NODE_ENV !== 'production' && has[id] != null) {
|
|
|
@@ -85,6 +99,7 @@ function runBatcherQueue (queue) {
|
|
|
export function pushWatcher (watcher) {
|
|
|
var id = watcher.id
|
|
|
if (has[id] == null) {
|
|
|
+ console.log('push: ' + id)
|
|
|
if (internalQueueDepleted && !watcher.user) {
|
|
|
// an internal watcher triggered by a user watcher...
|
|
|
// let's run it immediately after current user watcher is done.
|