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()
|
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])
|
||||||
|
|
Loading…
Reference in a new issue