21 lines
624 B
JavaScript
21 lines
624 B
JavaScript
import { directive } from '../directives'
|
|
import { destroyTree, initTree } from '../lifecycle'
|
|
import { mutateDom } from '../mutation'
|
|
|
|
directive('html', (el, { expression }, { effect, evaluateLater }) => {
|
|
let evaluate = evaluateLater(expression)
|
|
|
|
effect(() => {
|
|
evaluate(value => {
|
|
mutateDom(() => {
|
|
Array.from(el.children).forEach(child => destroyTree(child))
|
|
el.innerHTML = value ?? ''
|
|
|
|
el._x_ignoreSelf = true
|
|
initTree(el)
|
|
delete el._x_ignoreSelf
|
|
})
|
|
})
|
|
}, { priority: 'structural' })
|
|
})
|