diff --git a/playground/package.json b/playground/package.json index 2e4d2f104..b79c722f8 100644 --- a/playground/package.json +++ b/playground/package.json @@ -12,7 +12,7 @@ "vue": "workspace:*" }, "devDependencies": { - "@vitejs/plugin-vue": "^4.5.0", + "@vitejs/plugin-vue": "npm:@vue-vapor/vite-plugin-vue@latest", "vite": "^5.0.2", "vite-hyper-config": "^0.2.1", "vite-plugin-inspect": "^0.7.42" diff --git a/playground/src/main.ts b/playground/src/main.ts index c2246c045..9a1ec2f79 100644 --- a/playground/src/main.ts +++ b/playground/src/main.ts @@ -1,13 +1,18 @@ import { render, unmountComponent } from 'vue/vapor' +import { createApp } from 'vue' import './style.css' const modules = import.meta.glob('./*.(vue|js)') const mod = (modules['.' + location.pathname] || modules['./App.vue'])() mod.then(({ default: mod }) => { - const instance = render(mod, {}, '#app') - // @ts-expect-error - globalThis.unmount = () => { - unmountComponent(instance) + if (mod.vapor) { + const instance = render(mod, {}, '#app') + // @ts-expect-error + globalThis.unmount = () => { + unmountComponent(instance) + } + } else { + createApp(mod).mount('#app') } }) diff --git a/playground/src/props.js b/playground/src/props.js index e2d0d0c76..71cbfa080 100644 --- a/playground/src/props.js +++ b/playground/src/props.js @@ -1,15 +1,20 @@ -import { watch } from 'vue' +// @ts-check import { children, + defineComponent, on, ref, render as renderComponent, setText, template, - watchEffect, // TODO: + watch, + watchEffect, } from '@vue/vapor' -export default { +const t0 = template('') + +export default defineComponent({ + vapor: true, props: undefined, setup(_, {}) { @@ -29,21 +34,18 @@ export default { }, render(_ctx) { - const t0 = template('') const n0 = t0() - const { - 0: [n1], - } = children(n0) - on(n1, 'click', _ctx.handleClick) + const n1 = /** @type {HTMLButtonElement} */ (children(n0, 0)) + on(n1, 'click', () => _ctx.handleClick) watchEffect(() => { - setText(n1, void 0, _ctx.count) + setText(n1, _ctx.count) }) // TODO: create component fn? // const c0 = createComponent(...) // insert(n0, c0) renderComponent( - child, + /** @type {any} */ (child), // TODO: proxy?? { @@ -62,9 +64,12 @@ export default { return n0 }, -} +}) + +const t1 = template('

') +const child = defineComponent({ + vapor: true, -const child = { props: { count: { type: Number, default: 1 }, inlineDouble: { type: Number, default: 2 }, @@ -79,26 +84,14 @@ const child = { () => props.inlineDouble, v => console.log('inlineDouble changed', v), ) - - const __returned__ = {} - - Object.defineProperty(__returned__, '__isScriptSetup', { - enumerable: false, - value: true, - }) - - return __returned__ }, render(_ctx) { - const t0 = template('

') - const n0 = t0() - const { - 0: [n1], - } = children(n0) + const n0 = t1() + const n1 = children(n0, 0) watchEffect(() => { setText(n1, void 0, _ctx.count + ' * 2 = ' + _ctx.inlineDouble) }) return n0 }, -} +}) diff --git a/playground/src/reactive-event-handler.vue b/playground/src/reactive-event-handler.vue index 68a7af723..4ec0fb667 100644 --- a/playground/src/reactive-event-handler.vue +++ b/playground/src/reactive-event-handler.vue @@ -1,5 +1,5 @@