refactor(runtime-vapor): clean up

This commit is contained in:
三咲智子 Kevin Deng 2023-12-15 01:30:26 +08:00
parent 6eaf4b651b
commit 9dda97e736
No known key found for this signature in database
GPG Key ID: 69992F2250DFD93E
5 changed files with 8 additions and 29 deletions

View File

@ -4,13 +4,11 @@ import {
effect, effect,
setText, setText,
render, render,
getCurrentInstance,
ref, ref,
unmountComponent, unmountComponent,
} from '../src' } from '../src'
import type { ComponentInternalInstance } from '../src'
import { afterEach, beforeEach, describe, expect } from 'vitest' import { afterEach, beforeEach, describe, expect } from 'vitest'
import { defineComponent, nextTick } from '@vue/runtime-core' import { defineComponent } from '@vue/runtime-core'
let host: HTMLElement let host: HTMLElement
@ -42,7 +40,6 @@ describe('component', () => {
}, },
}) })
const instance = render(Comp as any, {}, '#host') const instance = render(Comp as any, {}, '#host')
await nextTick()
expect(host.innerHTML).toBe('<div>0</div>') expect(host.innerHTML).toBe('<div>0</div>')
unmountComponent(instance) unmountComponent(instance)
expect(host.innerHTML).toBe('') expect(host.innerHTML).toBe('')

View File

@ -1,7 +1,3 @@
/**
* @vitest-environment jsdom
*/
import { template, fragment } from '../src' import { template, fragment } from '../src'
describe('api: template', () => { describe('api: template', () => {

View File

@ -24,26 +24,14 @@ describe('directive: v-show', () => {
function handleClick() { function handleClick() {
visible.value = !visible.value visible.value = !visible.value
} }
const __returned__ = { visible, handleClick }
Object.defineProperty(__returned__, '__isScriptSetup', {
enumerable: false,
value: true,
})
return __returned__
},
render(_ctx: any) {
const t0 = template('<button>toggle</button><h1>hello world</h1>') const t0 = template('<button>toggle</button><h1>hello world</h1>')
const n0 = t0() const n0 = t0()
const { const {
0: [n1], 0: [n1],
1: [n2], 1: [n2],
} = children(n0 as ChildNode) } = children(n0)
withDirectives(n2, [[vShow, () => _ctx.visible]]) withDirectives(n2, [[vShow, () => visible.value]])
on( on(n1 as HTMLElement, 'click', (...args) => handleClick(...args))
n1 as HTMLElement,
'click',
(...args) => _ctx.handleClick && _ctx.handleClick(...args),
)
return n0 return n0
}, },
}) })

View File

@ -1,6 +1,5 @@
import { markRaw, proxyRefs } from '@vue/reactivity' import { markRaw, proxyRefs } from '@vue/reactivity'
import { type Data } from '@vue/shared' import { type Data } from '@vue/shared'
import { import {
type Component, type Component,
type ComponentInternalInstance, type ComponentInternalInstance,
@ -8,11 +7,8 @@ import {
setCurrentInstance, setCurrentInstance,
unsetCurrentInstance, unsetCurrentInstance,
} from './component' } from './component'
import { initProps } from './componentProps' import { initProps } from './componentProps'
import { invokeDirectiveHook } from './directive' import { invokeDirectiveHook } from './directive'
import { insert, remove } from './dom' import { insert, remove } from './dom'
import { PublicInstanceProxyHandlers } from './componentPublicInstance' import { PublicInstanceProxyHandlers } from './componentPublicInstance'
@ -61,7 +57,9 @@ export function mountComponent(
} else { } else {
block = state as Block block = state as Block
} }
if (block instanceof DocumentFragment) block = Array.from(block.childNodes) if (block instanceof DocumentFragment) {
block = Array.from(block.childNodes)
}
return (instance.block = block) return (instance.block = block)
})! })!
invokeDirectiveHook(instance, 'beforeMount') invokeDirectiveHook(instance, 'beforeMount')

View File

@ -20,7 +20,7 @@ function flush() {
queued = undefined queued = undefined
} }
export const nextTick = (fn: any) => p.then(fn) export const nextTick = (fn?: any) => (fn ? p.then(fn) : p)
export function effect(fn: any) { export function effect(fn: any) {
let run: () => void let run: () => void