Add support for HTML elements to listener binding
This commit is contained in:
parent
945736b9a9
commit
5036259d75
2 changed files with 7 additions and 2 deletions
|
@ -45,7 +45,10 @@ export const bind = (listener, prop, target=document.createTextNode(""), filter)
|
|||
? filter(data)
|
||||
: data
|
||||
if ("innerText" in target)
|
||||
target.innerText = data
|
||||
if (typeof data == "string")
|
||||
target.innerText = data
|
||||
else
|
||||
target.replaceChildren(data)
|
||||
else
|
||||
target.data = data
|
||||
}
|
||||
|
|
|
@ -22,7 +22,9 @@ bind(listener, "value")
|
|||
bind(listener, "value", html_element)
|
||||
// Binds an existng HTML or Text node
|
||||
bind(listener, "value", html_element, value => value.toUpperCase())
|
||||
// Filters the value through a function before setting it
|
||||
// Accepts a function to transform the value
|
||||
bind(listener, "value", html_element, value => document.createElement("hr"))
|
||||
// Also accepts HTML elements when the target is not a text node
|
||||
```
|
||||
|
||||
## Example
|
||||
|
|
Loading…
Reference in a new issue