This commit is contained in:
2026-04-13 18:10:32 +02:00
parent 7aac307af5
commit 1d09e8b382

View File

@@ -200,29 +200,35 @@ const Tag = (tag, props = {}, children = []) => {
props = {} props = {}
} }
if (isFunc(tag)) { if (isFunc(tag)) {
const ctx = { _mounts: [], _cleanups: new Set() } const ctx = { _mounts: [], _cleanups: new Set() }
const effect = createEffect(() => { const effect = createEffect(() => {
const result = tag(props, { const result = tag(props, {
children, children,
emit: (ev, ...args) => props[`on${ev[0].toUpperCase()}${ev.slice(1)}`]?.(...args) emit: (ev, ...args) => props[`on${ev[0].toUpperCase()}${ev.slice(1)}`]?.(...args)
})
effect._result = result
return result
}) })
effect() effect._result = result
ctx._mounts = effect._mounts || [] return result
ctx._cleanups = effect._cleanups || new Set() })
const result = effect._result effect()
const attachLifecycle = node => node && typeof node === 'object' && !node._isRuntime && (
node._mounts = ctx._mounts, const result = effect._result
node._cleanups = ctx._cleanups, if (result == null) return null
node._ownerEffect = effect
) const node = (result instanceof Node || (isArr(result) && result.every(n => n instanceof Node)))
isArr(result) ? result.forEach(attachLifecycle) : attachLifecycle(result) ? result
if (result == null) return null : doc.createTextNode(String(result))
if (result instanceof Node || (isArr(result) && result.every(n => n instanceof Node))) return result
return doc.createTextNode(String(result)) const attach = n => {
if (isObj(n) && !n._isRuntime) {
n._mounts = effect._mounts || []
n._cleanups = effect._cleanups || new Set()
n._ownerEffect = effect
}
} }
isArr(node) ? node.forEach(attach) : attach(node)
return node
}
const isSVG = /^(svg|path|circle|rect|line|polyline|polygon|g|defs|text|tspan|use)$/.test(tag) const isSVG = /^(svg|path|circle|rect|line|polyline|polygon|g|defs|text|tspan|use)$/.test(tag)
const el = isSVG ? doc.createElementNS("http://www.w3.org/2000/svg", tag) : doc.createElement(tag) const el = isSVG ? doc.createElementNS("http://www.w3.org/2000/svg", tag) : doc.createElement(tag)
el._cleanups = new Set() el._cleanups = new Set()