Use static object for api command handlers

This commit is contained in:
toasted-nutbread 2019-10-02 20:47:03 -04:00
parent 10458c63e7
commit 0d6177398d

View File

@ -126,7 +126,13 @@ async function apiTemplateRender(template, data, dynamic) {
} }
async function apiCommandExec(command) { async function apiCommandExec(command) {
const handlers = { const handlers = apiCommandExec.handlers;
if (handlers.hasOwnProperty(command)) {
const handler = handlers[command];
handler();
}
}
apiCommandExec.handlers = {
search: () => { search: () => {
chrome.tabs.create({url: chrome.extension.getURL('/bg/search.html')}); chrome.tabs.create({url: chrome.extension.getURL('/bg/search.html')});
}, },
@ -150,12 +156,6 @@ async function apiCommandExec(command) {
} }
}; };
const handler = handlers[command];
if (handler) {
handler();
}
}
async function apiAudioGetUrl(definition, source) { async function apiAudioGetUrl(definition, source) {
return audioBuildUrl(definition, source); return audioBuildUrl(definition, source);
} }