From 4c4a2ab65f6dde0802c7d0ee7fd3200c45316488 Mon Sep 17 00:00:00 2001 From: kingwl <805037171@163.com> Date: Tue, 21 Mar 2017 15:20:57 +0800 Subject: [PATCH] trigger event after reassigned state - Fix #5191 (#5233) --- src/core/observer/scheduler.js | 10 ++++--- test/unit/modules/observer/scheduler.spec.js | 31 ++++++++++++++++++++ 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/core/observer/scheduler.js b/src/core/observer/scheduler.js index 08182e1b..04d03488 100644 --- a/src/core/observer/scheduler.js +++ b/src/core/observer/scheduler.js @@ -69,10 +69,14 @@ function flushSchedulerQueue () { } } + // reset scheduler before updated hook called + const oldQueue = queue.slice() + resetSchedulerState() + // call updated hooks - index = queue.length + index = oldQueue.length while (index--) { - watcher = queue[index] + watcher = oldQueue[index] vm = watcher.vm if (vm._watcher === watcher && vm._isMounted) { callHook(vm, 'updated') @@ -84,8 +88,6 @@ function flushSchedulerQueue () { if (devtools && config.devtools) { devtools.emit('flush') } - - resetSchedulerState() } /** diff --git a/test/unit/modules/observer/scheduler.spec.js b/test/unit/modules/observer/scheduler.spec.js index b17aaf3d..14219793 100644 --- a/test/unit/modules/observer/scheduler.spec.js +++ b/test/unit/modules/observer/scheduler.spec.js @@ -144,4 +144,35 @@ describe('Scheduler', () => { expect(callOrder).toEqual([1, 2, 3]) }).then(done) }) + + // Github issue #5191 + it('emit should work when updated hook called', done => { + const el = document.createElement('div') + const vm = new Vue({ + template: `