Turn __raw into static listener.raw

This commit is contained in:
Talia 2022-02-15 15:50:20 +01:00
parent a2d2b42c76
commit 737fb6d155

View file

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