Skip to content

Commit 403a800

Browse files
committed
feat(vue-jsx-vapor): support vaporComponent for createNodes
1 parent 1c25275 commit 403a800

File tree

5 files changed

+590
-469
lines changed

5 files changed

+590
-469
lines changed

docs/introduction/getting-started.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ We assume you are already familiar with the basic usages of Vue before you conti
2525
pnpm add vue-jsx-vapor
2626

2727
# runtime
28-
pnpm add https://pkg.pr.new/vue@42f38ca
28+
pnpm add https://pkg.pr.new/vue@d386396
2929
```
3030

3131
The Vue Vapor runtime is not release, so we use [pkg.pr.new](https://github.com/stackblitz-labs/pkg.pr.new) to install.

packages/vue-jsx-vapor/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@
191191
"esbuild": "*",
192192
"rollup": "^3",
193193
"vite": ">=3",
194+
"vue": "^3.5.0",
194195
"webpack": "^4 || ^5"
195196
},
196197
"peerDependenciesMeta": {

packages/vue-jsx-vapor/src/core/runtime.ts

+12-9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
effectScope,
33
insert,
44
isFragment,
5+
isVaporComponent,
56
remove,
67
renderEffect,
78
VaporFragment,
@@ -12,27 +13,29 @@ import {
1213
export { shallowRef as useRef } from 'vue'
1314

1415
function createFragment(
15-
nodes: Block[],
16+
nodes: Block,
1617
anchor: Node | undefined = document.createTextNode(''),
1718
) {
1819
const frag = new VaporFragment(nodes)
1920
frag.anchor = anchor
2021
return frag
2122
}
2223

23-
function normalizeValue(value: any, anchor?: Element): Block {
24-
if (value instanceof Node || isFragment(value)) {
24+
function normalizeNode(node: any, anchor?: Element): Block {
25+
if (node instanceof Node || isFragment(node)) {
2526
anchor && (anchor.textContent = '')
26-
return value
27-
} else if (Array.isArray(value)) {
27+
return node
28+
} else if (isVaporComponent(node)) {
29+
anchor && (anchor.textContent = '')
30+
return createFragment(node, anchor)
31+
} else if (Array.isArray(node)) {
2832
anchor && (anchor.textContent = '')
2933
return createFragment(
30-
value.map((i) => normalizeValue(i)),
34+
node.map((i) => normalizeNode(i)),
3135
anchor,
3236
)
3337
} else {
34-
const result =
35-
value == null || typeof value === 'boolean' ? '' : String(value)
38+
const result = node == null || typeof node === 'boolean' ? '' : String(node)
3639
if (anchor) {
3740
anchor.textContent = result
3841
return anchor
@@ -43,7 +46,7 @@ function normalizeValue(value: any, anchor?: Element): Block {
4346
}
4447

4548
function resolveValue(current: Block, value: any, anchor?: Element) {
46-
const node = normalizeValue(value, anchor)
49+
const node = normalizeNode(value, anchor)
4750
if (current) {
4851
if (isFragment(current)) {
4952
const { anchor } = current

0 commit comments

Comments
 (0)