|
|
@@ -1,11 +1,10 @@
|
|
|
+import { onEffectCleanup } from '@vue/reactivity'
|
|
|
import {
|
|
|
nextTick,
|
|
|
onBeforeUpdate,
|
|
|
onUpdated,
|
|
|
- onWatcherCleanup,
|
|
|
ref,
|
|
|
renderEffect,
|
|
|
- renderWatch,
|
|
|
template,
|
|
|
watchEffect,
|
|
|
watchPostEffect,
|
|
|
@@ -31,8 +30,8 @@ const createDemo = (setupFn: () => any, renderFn: (ctx: any) => any) =>
|
|
|
},
|
|
|
})
|
|
|
|
|
|
-describe('renderWatch', () => {
|
|
|
- test('effect', async () => {
|
|
|
+describe('renderEffect', () => {
|
|
|
+ test('basic', async () => {
|
|
|
let dummy: any
|
|
|
const source = ref(0)
|
|
|
renderEffect(() => {
|
|
|
@@ -58,26 +57,6 @@ describe('renderWatch', () => {
|
|
|
expect(dummy).toBe(3)
|
|
|
})
|
|
|
|
|
|
- test('watch', async () => {
|
|
|
- let dummy: any
|
|
|
- const source = ref(0)
|
|
|
- renderWatch(source, () => {
|
|
|
- dummy = source.value
|
|
|
- })
|
|
|
- await nextTick()
|
|
|
- expect(dummy).toBe(undefined)
|
|
|
-
|
|
|
- source.value++
|
|
|
- expect(dummy).toBe(undefined)
|
|
|
- await nextTick()
|
|
|
- expect(dummy).toBe(1)
|
|
|
-
|
|
|
- source.value++
|
|
|
- expect(dummy).toBe(1)
|
|
|
- await nextTick()
|
|
|
- expect(dummy).toBe(2)
|
|
|
- })
|
|
|
-
|
|
|
test('should run with the scheduling order', async () => {
|
|
|
const calls: string[] = []
|
|
|
|
|
|
@@ -101,17 +80,17 @@ describe('renderWatch', () => {
|
|
|
watchPostEffect(() => {
|
|
|
const current = source.value
|
|
|
calls.push(`post ${current}`)
|
|
|
- onWatcherCleanup(() => calls.push(`post cleanup ${current}`))
|
|
|
+ onEffectCleanup(() => calls.push(`post cleanup ${current}`))
|
|
|
})
|
|
|
watchEffect(() => {
|
|
|
const current = source.value
|
|
|
calls.push(`pre ${current}`)
|
|
|
- onWatcherCleanup(() => calls.push(`pre cleanup ${current}`))
|
|
|
+ onEffectCleanup(() => calls.push(`pre cleanup ${current}`))
|
|
|
})
|
|
|
watchSyncEffect(() => {
|
|
|
const current = source.value
|
|
|
calls.push(`sync ${current}`)
|
|
|
- onWatcherCleanup(() => calls.push(`sync cleanup ${current}`))
|
|
|
+ onEffectCleanup(() => calls.push(`sync cleanup ${current}`))
|
|
|
})
|
|
|
return { source, change, renderSource, changeRender }
|
|
|
},
|
|
|
@@ -121,15 +100,8 @@ describe('renderWatch', () => {
|
|
|
renderEffect(() => {
|
|
|
const current = _ctx.renderSource
|
|
|
calls.push(`renderEffect ${current}`)
|
|
|
- onWatcherCleanup(() => calls.push(`renderEffect cleanup ${current}`))
|
|
|
+ onEffectCleanup(() => calls.push(`renderEffect cleanup ${current}`))
|
|
|
})
|
|
|
- renderWatch(
|
|
|
- () => _ctx.renderSource,
|
|
|
- value => {
|
|
|
- calls.push(`renderWatch ${value}`)
|
|
|
- onWatcherCleanup(() => calls.push(`renderWatch cleanup ${value}`))
|
|
|
- },
|
|
|
- )
|
|
|
},
|
|
|
).render()
|
|
|
const { change, changeRender } = instance.setupState as any
|
|
|
@@ -151,7 +123,6 @@ describe('renderWatch', () => {
|
|
|
'beforeUpdate 1',
|
|
|
'renderEffect cleanup 0',
|
|
|
'renderEffect 1',
|
|
|
- 'renderWatch 1',
|
|
|
'post cleanup 0',
|
|
|
'post 1',
|
|
|
'updated 1',
|
|
|
@@ -172,8 +143,6 @@ describe('renderWatch', () => {
|
|
|
'beforeUpdate 2',
|
|
|
'renderEffect cleanup 1',
|
|
|
'renderEffect 2',
|
|
|
- 'renderWatch cleanup 1',
|
|
|
- 'renderWatch 2',
|
|
|
'post cleanup 1',
|
|
|
'post 2',
|
|
|
'updated 2',
|