fix(reactivity): ensure computed always expose value

fix #3099

Also changes the original fix for #910 by moving the fix from
reactivity to the scheduler
This commit is contained in:
Evan You
2021-05-27 20:53:21 -04:00
parent 32e21333dd
commit 03a7a73148
5 changed files with 52 additions and 42 deletions

View File

@@ -1,3 +1,4 @@
import { effect, stop } from '@vue/reactivity'
import {
queueJob,
nextTick,
@@ -568,4 +569,27 @@ describe('scheduler', () => {
await nextTick()
expect(count).toBe(1)
})
// #910
test('should not run stopped reactive effects', async () => {
const spy = jest.fn()
// simulate parent component that toggles child
const job1 = () => {
stop(job2)
}
job1.id = 0 // need the id to ensure job1 is sorted before job2
// simulate child that's triggered by the same reactive change that
// triggers its toggle
const job2 = effect(() => spy())
expect(spy).toHaveBeenCalledTimes(1)
queueJob(job1)
queueJob(job2)
await nextTick()
// should not be called again
expect(spy).toHaveBeenCalledTimes(1)
})
})