diff options
author | Alex Yatskov <alex@foosoft.net> | 2020-01-04 11:54:54 -0800 |
---|---|---|
committer | Alex Yatskov <alex@foosoft.net> | 2020-01-04 11:54:54 -0800 |
commit | 2a12036ca305044291f1f4105d6a8d249848b210 (patch) | |
tree | 5cfd4a3d837bf99730233a805d72395c8c61fc07 /ext/fg/js/frontend-api-receiver.js | |
parent | 9105cb5618cfdd14c2bc37cd22db2b360fe8cd52 (diff) | |
parent | 174b92366577b0a638003b15e2d73fdc91cd62c3 (diff) |
Merge branch 'master' into testing
Diffstat (limited to 'ext/fg/js/frontend-api-receiver.js')
-rw-r--r-- | ext/fg/js/frontend-api-receiver.js | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/ext/fg/js/frontend-api-receiver.js b/ext/fg/js/frontend-api-receiver.js index 7d38ddd5..642d96df 100644 --- a/ext/fg/js/frontend-api-receiver.js +++ b/ext/fg/js/frontend-api-receiver.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 Alex Yatskov <alex@foosoft.net> + * Copyright (C) 2019-2020 Alex Yatskov <alex@foosoft.net> * Author: Alex Yatskov <alex@foosoft.net> * * This program is free software: you can redistribute it and/or modify @@ -13,14 +13,14 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. + * along with this program. If not, see <https://www.gnu.org/licenses/>. */ 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}); |