Allow returning text in skooma bind method
This commit is contained in:
parent
8d9dc8ae7f
commit
939c564f03
2 changed files with 11 additions and 5 deletions
|
@ -297,6 +297,7 @@
|
|||
Therefore one cannot use tagged template literals with <code>text</code>
|
||||
as this would return a document fragment which cannot be replaced.
|
||||
</div>
|
||||
If the element is a string, it is turned into a text node before insertion.
|
||||
</dd>
|
||||
<dt>Update function</dt>
|
||||
<code>
|
||||
|
|
|
@ -81,9 +81,9 @@ const node = (name, args, options) => {
|
|||
const custom = getCustom(args)
|
||||
if ("nameFilter" in options) name = options.nameFilter(name)
|
||||
if (options.xmlns)
|
||||
element = document.createElementNS(options.xmlns, name, {is: custom})
|
||||
element = document.createElementNS(options.xmlns, name, custom ?? {is: custom})
|
||||
else
|
||||
element = document.createElement(name, {is: custom})
|
||||
element = document.createElement(name, custom ?? {is: custom})
|
||||
parseArgs(element, null, args)
|
||||
return element
|
||||
}
|
||||
|
@ -104,11 +104,16 @@ export const bind = transform => {
|
|||
const update = (...data) => {
|
||||
const next = transform(...data)
|
||||
if (next) {
|
||||
if (typeof next == "string") {
|
||||
element.innerText = next
|
||||
return element
|
||||
} else {
|
||||
if (element) element.replaceWith(next)
|
||||
element = inject(next)
|
||||
return element
|
||||
}
|
||||
}
|
||||
}
|
||||
return update
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue