use duck typing for event listener
This commit is contained in:
parent
067c26982e
commit
123e725049
@ -325,7 +325,13 @@ const yomichan = (() => {
|
|||||||
reject = _reject;
|
reject = _reject;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (eventHandler === chrome.runtime.onMessage) {
|
if (
|
||||||
|
typeof eventHandler.addListener === 'undefined' ||
|
||||||
|
typeof eventHandler.removeListener === 'undefined'
|
||||||
|
) {
|
||||||
|
throw new Error('Event handler type not supported');
|
||||||
|
}
|
||||||
|
|
||||||
const runtimeMessageCallback = ({action, params}, sender, sendResponse) => {
|
const runtimeMessageCallback = ({action, params}, sender, sendResponse) => {
|
||||||
let timeoutId = null;
|
let timeoutId = null;
|
||||||
if (timeout !== null) {
|
if (timeout !== null) {
|
||||||
@ -350,9 +356,6 @@ const yomichan = (() => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
eventHandler.addListener(runtimeMessageCallback);
|
eventHandler.addListener(runtimeMessageCallback);
|
||||||
} else {
|
|
||||||
throw new Error('Event handler type not supported');
|
|
||||||
}
|
|
||||||
|
|
||||||
return listenerPromise;
|
return listenerPromise;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user