aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2017-10-11 08:15:14 +0800
committerkumavis <aaron@kumavis.me>2017-10-11 08:15:14 +0800
commite32d75965f848f8b26868b6476265e61b791c768 (patch)
treeb020d8b554779087580cf27cb00d08fcffaa659b
parent4d273d3ceade861d24dceed96a0f5d5f3dc229ae (diff)
downloadtangerine-wallet-browser-e32d75965f848f8b26868b6476265e61b791c768.tar
tangerine-wallet-browser-e32d75965f848f8b26868b6476265e61b791c768.tar.gz
tangerine-wallet-browser-e32d75965f848f8b26868b6476265e61b791c768.tar.bz2
tangerine-wallet-browser-e32d75965f848f8b26868b6476265e61b791c768.tar.lz
tangerine-wallet-browser-e32d75965f848f8b26868b6476265e61b791c768.tar.xz
tangerine-wallet-browser-e32d75965f848f8b26868b6476265e61b791c768.tar.zst
tangerine-wallet-browser-e32d75965f848f8b26868b6476265e61b791c768.zip
events-proxy - clean up
-rw-r--r--app/scripts/lib/events-proxy.js10
1 files changed, 5 insertions, 5 deletions
diff --git a/app/scripts/lib/events-proxy.js b/app/scripts/lib/events-proxy.js
index d1199a278..840b06b1a 100644
--- a/app/scripts/lib/events-proxy.js
+++ b/app/scripts/lib/events-proxy.js
@@ -1,6 +1,5 @@
-module.exports = function createEventEmitterProxy(eventEmitter, listeners) {
+module.exports = function createEventEmitterProxy(eventEmitter, eventHandlers = {}) {
let target = eventEmitter
- const eventHandlers = listeners || {}
const proxy = new Proxy({}, {
get: (obj, name) => {
// intercept listeners
@@ -14,9 +13,12 @@ module.exports = function createEventEmitterProxy(eventEmitter, listeners) {
return true
},
})
+ proxy.setTarget(eventEmitter)
+ return proxy
+
function setTarget (eventEmitter) {
target = eventEmitter
- // migrate listeners
+ // migrate eventHandlers
Object.keys(eventHandlers).forEach((name) => {
eventHandlers[name].forEach((handler) => target.on(name, handler))
})
@@ -26,6 +28,4 @@ module.exports = function createEventEmitterProxy(eventEmitter, listeners) {
eventHandlers[name].push(handler)
target.on(name, handler)
}
- if (listeners) proxy.setTarget(eventEmitter)
- return proxy
} \ No newline at end of file