import {
render,
html,
component,
useState,
useEffect,
useMemo,
ReactiveElement,
dynamic,
repeat,
keep,
setAlive
} from '@gallop/gallop'
component('test-b', ({ text }: { text: string }) => {
const [state] = useState({ b: 1 })
return html`
this is test b ${text}
state is ${state.b}
`
})
component('test-mmm', function (
this: ReactiveElement,
{ name }: { name?: string } = {}
) {
const [state] = useState({
a: 1,
b: 2,
arr: [1, 2, 3, 4, 5, 6, 7, 8, 9],
checked: false,
rand: [1]
})
const { a, b } = state
const memo = useMemo(() => a + b, [a, b])
useEffect(() => {
const button = this.$root.querySelector('button')
setTimeout(() => button?.click(), 1000)
}, [])
return html`
${name}
${memo}
${dynamic({
name: 'test-b',
props: { text: 'haha' },
inner: html`
${memo} in test-b slot
`
})}
${repeat(
state.arr,
(item) => item,
(item) => html`
console.log(item)}">${item}
`
)}
${repeat(
state.rand,
(item) => item,
(item) => html`
console.log(item)}">${item}
`
)}
${repeat(
state.arr,
(item) => item,
(item) => html`
console.log(item)}">${item}
`
)}
{
const target = e.target as HTMLInputElement
state.checked = target.checked
}}"
/>
${state.checked}
keepalive
${keep(
a % 2
? html`
`.do(setAlive, +true)
: null
)}
${html`
${html`
caption
`}
${html`
${html``}
`}
${html``}
${html`
${html`
${html`1 | `}
`}
`}
${html`
foot |
`}
`}
`
})
render(html` `)