Rename bind to bindContent in listener.js
This is partly to avoid confusion with the skooma `bind` function, but also to make it clearer that only the inner content of an element is being bound to the listener. This function may also disappear entirely in the future if it turns out it doesn't provide any benefits over the skooma bind function.
This commit is contained in:
parent
8161b80081
commit
f612273632
2 changed files with 8 additions and 5 deletions
|
@ -39,7 +39,7 @@ export const listener = (target={}) => {
|
||||||
return proxy
|
return proxy
|
||||||
}
|
}
|
||||||
|
|
||||||
export const bind = (listener, prop, target=document.createTextNode(""), filter) => {
|
export const bindContent = (listener, prop="value", target=document.createTextNode(""), filter) => {
|
||||||
const run = data => {
|
const run = data => {
|
||||||
data = filter
|
data = filter
|
||||||
? filter(data)
|
? filter(data)
|
||||||
|
|
11
listener.md
11
listener.md
|
@ -16,17 +16,20 @@ listener.listen(prop)
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
bind(listener, "value")
|
bindContent(listener, "value")
|
||||||
// Returns a text node with listener.value as its content
|
// Returns a text node with listener.value as its content
|
||||||
// that will change whenever the value is changed
|
// that will change whenever the value is changed
|
||||||
bind(listener, "value", html_element)
|
bindContent(listener, "value", html_element)
|
||||||
// Binds an existng HTML or Text node
|
// Binds an existng HTML or Text node
|
||||||
bind(listener, "value", html_element, value => value.toUpperCase())
|
bindContent(listener, "value", html_element, value => value.toUpperCase())
|
||||||
// Accepts a function to transform the value
|
// Accepts a function to transform the value
|
||||||
bind(listener, "value", html_element, value => document.createElement("hr"))
|
bindContent(listener, "value", html_element, value => document.createElement("hr"))
|
||||||
// Also accepts HTML elements when the target is not a text node
|
// Also accepts HTML elements when the target is not a text node
|
||||||
```
|
```
|
||||||
|
|
||||||
|
This function *may* be **removed** in the future if it doesn't show any
|
||||||
|
usefullnes that isn't already provided by the skooma bind function.
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|
Loading…
Reference in a new issue