From 737fb6d155a666032e58495805c482f46e03bdee Mon Sep 17 00:00:00 2001 From: DarkWiiPlayer Date: Tue, 15 Feb 2022 15:50:20 +0100 Subject: [PATCH] Turn __raw into static listener.raw --- listener.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/listener.js b/listener.js index 3808db9..ffe39ac 100644 --- a/listener.js +++ b/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])