Turn __raw into static listener.raw

This commit is contained in:
Talia 2022-02-15 15:50:20 +01:00
parent a2d2b42c76
commit 737fb6d155
1 changed files with 8 additions and 8 deletions

View File

@ -8,6 +8,8 @@ Example:
l.contract = new Contract()
*/
const registry = new Map()
export const listener = (target={}) => {
let callbacks = new Map()
function listen(prop, callback) {
@ -27,18 +29,16 @@ export const listener = (target={}) => {
if (callbacks.has(prop)) callbacks.get(prop).forEach(callback => callback(value, prop, target[prop]))
return Reflect.set(target, prop, value)
},
get: (target, prop, value) => {
if (prop == "listen")
return listen
else if (prop == "__raw")
return target
else
return Reflect.get(target, prop)
}
get: (target, prop, value) => prop=="listen"
? listen
: target[prop]
})
registry.set(proxy, target)
return proxy
}
listener.raw = proxy => registry.get(proxy)
export const text = (listener, prop) => {
if (prop) {
const node = document.createTextNode(listener[prop])