diff options
Diffstat (limited to 'ext/fg/js/frontend-api-receiver.js')
-rw-r--r-- | ext/fg/js/frontend-api-receiver.js | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/ext/fg/js/frontend-api-receiver.js b/ext/fg/js/frontend-api-receiver.js index 7d38ddd5..8d5e52ee 100644 --- a/ext/fg/js/frontend-api-receiver.js +++ b/ext/fg/js/frontend-api-receiver.js @@ -18,9 +18,9 @@ class FrontendApiReceiver { - constructor(source='', handlers={}) { - this.source = source; - this.handlers = handlers; + constructor(source='', handlers=new Map()) { + this._source = source; + this._handlers = handlers; chrome.runtime.onConnect.addListener(this.onConnect.bind(this)); } @@ -32,16 +32,13 @@ class FrontendApiReceiver { } onMessage(port, {id, action, params, target, senderId}) { - if ( - target !== this.source || - !hasOwn(this.handlers, action) - ) { - return; - } + if (target !== this._source) { return; } + + const handler = this._handlers.get(action); + if (typeof handler !== 'function') { return; } this.sendAck(port, id, senderId); - const handler = this.handlers[action]; handler(params).then( (result) => { this.sendResult(port, id, senderId, {result}); |