2024-12-02 09:36:49 +08:00
|
|
|
import {
|
|
|
|
createComponentSimple,
|
|
|
|
// createFor,
|
|
|
|
createVaporApp,
|
|
|
|
delegate,
|
|
|
|
delegateEvents,
|
|
|
|
ref,
|
|
|
|
renderEffectSimple,
|
|
|
|
template,
|
|
|
|
} from 'vue/vapor'
|
2024-09-17 10:32:28 +08:00
|
|
|
|
2024-12-02 09:36:49 +08:00
|
|
|
function createForSimple(val: () => any, render: (i: number) => any) {
|
|
|
|
const l = val(),
|
|
|
|
arr = new Array(l)
|
|
|
|
for (let i = 0; i < l; i++) {
|
|
|
|
arr[i] = render(i)
|
|
|
|
}
|
|
|
|
return arr
|
|
|
|
}
|
2023-11-17 03:01:19 +08:00
|
|
|
|
2024-12-02 09:36:49 +08:00
|
|
|
const t0 = template('<h1>Vapor</h1>')
|
|
|
|
const App = {
|
|
|
|
vapor: true,
|
|
|
|
__name: 'App',
|
|
|
|
setup() {
|
|
|
|
return (_ctx => {
|
|
|
|
const n0 = t0()
|
|
|
|
const n1 = createForSimple(
|
|
|
|
() => 10000,
|
|
|
|
(i: number) => createComponentSimple(Comp, { count: i }),
|
|
|
|
)
|
|
|
|
return [n0, createComponentSimple(Counter), n1]
|
|
|
|
})()
|
|
|
|
},
|
|
|
|
}
|
2023-11-24 20:29:05 +08:00
|
|
|
|
2024-12-02 09:36:49 +08:00
|
|
|
const Counter = {
|
|
|
|
vapor: true,
|
|
|
|
__name: 'Counter',
|
|
|
|
setup() {
|
|
|
|
delegateEvents('click')
|
|
|
|
const count = ref(0)
|
|
|
|
const button = document.createElement('button')
|
|
|
|
button.textContent = '++'
|
|
|
|
delegate(button, 'click', () => () => count.value++)
|
|
|
|
return [
|
|
|
|
button,
|
|
|
|
createComponentSimple(Comp, {
|
|
|
|
// if ref
|
|
|
|
count,
|
|
|
|
// if exp
|
|
|
|
get plusOne() {
|
|
|
|
return count.value + 1
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
// TODO dynamic props: merge with Proxy that iterates sources on access
|
|
|
|
]
|
|
|
|
},
|
|
|
|
}
|
2024-03-16 18:54:36 +08:00
|
|
|
|
2024-12-02 09:36:49 +08:00
|
|
|
const t0$1 = template('<div></div>')
|
|
|
|
const Comp = {
|
|
|
|
vapor: true,
|
|
|
|
__name: 'Comp',
|
|
|
|
setup(props: any) {
|
|
|
|
return (_ctx => {
|
|
|
|
const n = t0$1()
|
|
|
|
renderEffectSimple(() => {
|
|
|
|
n.textContent = props.count + ' / ' + props.plusOne
|
|
|
|
})
|
|
|
|
return n
|
|
|
|
})()
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
const s = performance.now()
|
|
|
|
const app = createVaporApp(App)
|
|
|
|
app.mount('#app')
|
|
|
|
console.log((performance.now() - s).toFixed(2))
|