vue3-core/playground/src/props.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

105 lines
1.9 KiB
JavaScript
Raw Normal View History

import { watch } from 'vue'
import {
children,
on,
ref,
2023-12-29 22:05:33 +08:00
render as renderComponent,
setText,
2023-12-29 22:05:33 +08:00
template,
watchEffect, // TODO:
} from '@vue/vapor'
export default {
props: undefined,
setup(_, {}) {
const count = ref(1)
const handleClick = () => {
count.value++
}
const __returned__ = { count, handleClick }
Object.defineProperty(__returned__, '__isScriptSetup', {
enumerable: false,
2023-12-29 22:05:33 +08:00
value: true,
})
return __returned__
},
render(_ctx) {
const t0 = template('<button></button>')
const n0 = t0()
const {
2023-12-29 22:05:33 +08:00
0: [n1],
} = children(n0)
on(n1, 'click', _ctx.handleClick)
watchEffect(() => {
setText(n1, void 0, _ctx.count)
})
// TODO: create component fn?
// const c0 = createComponent(...)
// insert(n0, c0)
renderComponent(
child,
// TODO: proxy??
{
/* <Comp :count="count" /> */
get count() {
return _ctx.count
},
/* <Comp :inline-double="count * 2" /> */
get inlineDouble() {
return _ctx.count * 2
2023-12-29 22:05:33 +08:00
},
},
2023-12-29 22:05:33 +08:00
n0,
)
return n0
2023-12-29 22:05:33 +08:00
},
}
const child = {
props: {
count: { type: Number, default: 1 },
2023-12-29 22:05:33 +08:00
inlineDouble: { type: Number, default: 2 },
},
setup(props) {
watch(
() => props.count,
2023-12-29 22:05:33 +08:00
v => console.log('count changed', v),
)
watch(
() => props.inlineDouble,
2023-12-29 22:05:33 +08:00
v => console.log('inlineDouble changed', v),
)
const __returned__ = {}
Object.defineProperty(__returned__, '__isScriptSetup', {
enumerable: false,
2023-12-29 22:05:33 +08:00
value: true,
})
return __returned__
},
render(_ctx) {
const t0 = template('<p></p>')
const n0 = t0()
const {
2023-12-29 22:05:33 +08:00
0: [n1],
} = children(n0)
watchEffect(() => {
setText(n1, void 0, _ctx.count + ' * 2 = ' + _ctx.inlineDouble)
})
return n0
2023-12-29 22:05:33 +08:00
},
}