Turn __raw into static listener.raw
This commit is contained in:
parent
a2d2b42c76
commit
737fb6d155
1 changed files with 8 additions and 8 deletions
16
listener.js
16
listener.js
|
@ -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])
|
||||
|
|
Loading…
Reference in a new issue