Change domLense method semantics
This commit is contained in:
parent
7a789d407e
commit
2b8ba6e7d6
1 changed files with 6 additions and 15 deletions
21
domLense.js
21
domLense.js
|
@ -24,12 +24,12 @@ export const lense = (methods, extra) => {
|
||||||
} else if (prop === Symbol.iterator) {
|
} else if (prop === Symbol.iterator) {
|
||||||
return function*() {
|
return function*() {
|
||||||
for (const child of target.children) {
|
for (const child of target.children) {
|
||||||
yield methods.get(child)
|
yield methods.get.call(child)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (prop.match?.call(prop, /^[0-9]+$/)) {
|
} else if (prop.match?.call(prop, /^[0-9]+$/)) {
|
||||||
const child = target.children[prop]
|
const child = target.children[prop]
|
||||||
if (child) return methods.get(child)
|
if (child) return methods.get.call(child)
|
||||||
return child
|
return child
|
||||||
} else {
|
} else {
|
||||||
return Array.prototype[prop]
|
return Array.prototype[prop]
|
||||||
|
@ -39,7 +39,7 @@ export const lense = (methods, extra) => {
|
||||||
if (prop.match?.call(prop, /^[0-9]+$/)) {
|
if (prop.match?.call(prop, /^[0-9]+$/)) {
|
||||||
const child = target.children[prop]
|
const child = target.children[prop]
|
||||||
if (child) {
|
if (child) {
|
||||||
methods.set(child, value)
|
methods.set.call(child, value)
|
||||||
return true
|
return true
|
||||||
} else {
|
} else {
|
||||||
for (let i = target.children.length; i < Number(prop); i++) {
|
for (let i = target.children.length; i < Number(prop); i++) {
|
||||||
|
@ -47,8 +47,8 @@ export const lense = (methods, extra) => {
|
||||||
}
|
}
|
||||||
const element = methods.new(value)
|
const element = methods.new(value)
|
||||||
target.appendChild(element)
|
target.appendChild(element)
|
||||||
if (methods.get(element) !== value)
|
if (methods.get.call(element) !== value)
|
||||||
methods.set(element, value)
|
methods.set.call(element, value)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
} else if (prop == "length") {
|
} else if (prop == "length") {
|
||||||
|
@ -70,16 +70,7 @@ export const lense = (methods, extra) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return element => {
|
return element => new Proxy(element, traps)
|
||||||
const proxy = new Proxy(element, traps)
|
|
||||||
|
|
||||||
if (methods.event) childObserver.observe(element)
|
|
||||||
if (typeof methods.event === "function") element.addEventListener("change", event => {
|
|
||||||
methods.event(proxy, element, event.detail)
|
|
||||||
})
|
|
||||||
|
|
||||||
return proxy
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default lense
|
export default lense
|
||||||
|
|
Loading…
Reference in a new issue