]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor(runtime-vapor): clean up
author三咲智子 Kevin Deng <sxzz@sxzz.moe>
Thu, 14 Dec 2023 17:30:26 +0000 (01:30 +0800)
committer三咲智子 Kevin Deng <sxzz@sxzz.moe>
Thu, 14 Dec 2023 17:30:34 +0000 (01:30 +0800)
packages/runtime-vapor/__tests__/component.spec.ts
packages/runtime-vapor/__tests__/template.spec.ts
packages/runtime-vapor/__tests__/vShow.spec.ts
packages/runtime-vapor/src/render.ts
packages/runtime-vapor/src/scheduler.ts

index 0d9b26f7a9ac94d4a99129c055d77d57c2139f85..549402a00c2cf7605c552da4e53ba3b0a824f5ae 100644 (file)
@@ -4,13 +4,11 @@ import {
   effect,
   setText,
   render,
-  getCurrentInstance,
   ref,
   unmountComponent,
 } from '../src'
-import type { ComponentInternalInstance } from '../src'
 import { afterEach, beforeEach, describe, expect } from 'vitest'
-import { defineComponent, nextTick } from '@vue/runtime-core'
+import { defineComponent } from '@vue/runtime-core'
 
 let host: HTMLElement
 
@@ -42,7 +40,6 @@ describe('component', () => {
       },
     })
     const instance = render(Comp as any, {}, '#host')
-    await nextTick()
     expect(host.innerHTML).toBe('<div>0</div>')
     unmountComponent(instance)
     expect(host.innerHTML).toBe('')
index df711722189163583a48894f204c44ed46d918d6..21d7808f4c4d5e1120b22214b9bbe35a65f93e0a 100644 (file)
@@ -1,7 +1,3 @@
-/**
- * @vitest-environment jsdom
- */
-
 import { template, fragment } from '../src'
 
 describe('api: template', () => {
index 66f5b4b1f00eca35b0c39b5c8b1aa771c49d87b9..fb1447e336ffef37657cc3e8ea95668670b94f8e 100644 (file)
@@ -24,26 +24,14 @@ describe('directive: v-show', () => {
         function handleClick() {
           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 n0 = t0()
         const {
           0: [n1],
           1: [n2],
-        } = children(n0 as ChildNode)
-        withDirectives(n2, [[vShow, () => _ctx.visible]])
-        on(
-          n1 as HTMLElement,
-          'click',
-          (...args) => _ctx.handleClick && _ctx.handleClick(...args),
-        )
+        } = children(n0)
+        withDirectives(n2, [[vShow, () => visible.value]])
+        on(n1 as HTMLElement, 'click', (...args) => handleClick(...args))
         return n0
       },
     })
index e39ace1d0778a039970b819c25bffe9603308708..123c9f5d8fff657170196636bca8767da8a5e6df 100644 (file)
@@ -1,6 +1,5 @@
 import { markRaw, proxyRefs } from '@vue/reactivity'
 import { type Data } from '@vue/shared'
-
 import {
   type Component,
   type ComponentInternalInstance,
@@ -8,11 +7,8 @@ import {
   setCurrentInstance,
   unsetCurrentInstance,
 } from './component'
-
 import { initProps } from './componentProps'
-
 import { invokeDirectiveHook } from './directive'
-
 import { insert, remove } from './dom'
 import { PublicInstanceProxyHandlers } from './componentPublicInstance'
 
@@ -61,7 +57,9 @@ export function mountComponent(
     } else {
       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)
   })!
   invokeDirectiveHook(instance, 'beforeMount')
index ec9535cabd6eba6212ab0defb3ea191eca0c9360..876e2c45e1b6ce28dc6082758f8b6b216e0f7696 100644 (file)
@@ -20,7 +20,7 @@ function flush() {
   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) {
   let run: () => void