-
Notifications
You must be signed in to change notification settings - Fork 223
Audio refactor #401
Audio refactor #401
Conversation
@@ -18,7 +18,7 @@ | |||
|
|||
/*global docRangeFromPoint, docSentenceExtract | |||
apiKanjiFind, apiTermsFind, apiNoteView, apiOptionsGet, apiDefinitionsAddable, apiDefinitionAdd | |||
apiScreenshotGet, apiForward, apiAudioGetUrl | |||
apiScreenshotGet, apiForward, apiAudioGetUri |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should these be made one per line, such as
/* global
* apiScreenshotGet
* apiForward
* apiAudioGetUri
*/
At the risk of taking up a bit more space, this would reduce the amount of conflicts to resolve.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would consider that outside of the scope of this change, but that sounds like a good idea. Particularly because, long-term, the number of global definitions should eventually be reduced. For example:
/* global
* apiScreenshotGet
* apiForward
* apiAudioGetUri
*/
Will likely eventually become:
/* global
* api
*/
The URL --> URI change got me curious, what is |
ext/bg/js/backend.js
Outdated
@@ -515,7 +515,7 @@ class Backend { | |||
|
|||
async _onApiAudioGetUrl({definition, source, optionsContext}) { | |||
const options = this.getOptions(optionsContext); | |||
return await audioGetUrl(definition, source, options); | |||
return await this.audioUriBuilder.getUri(source, definition, options); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think either AudioUriBuilder.getUri
should be changed to the definition, source, options
or the other way around, whichever is more desirable, to avoid confusion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll update source
to be the first argument consistently, since there's precedent for that in multiple places. There are a few places where this parameter is named either source
or mode
, and I'll try to settle on only one of those also.
yomichan/ext/bg/js/translator.js
Lines 144 to 157 in 0cd1f8f
async findTerms(mode, text, details, options) { | |
switch (mode) { | |
case 'group': | |
return await this.findTermsGrouped(text, details, options); | |
case 'merge': | |
return await this.findTermsMerged(text, details, options); | |
case 'split': | |
return await this.findTermsSplit(text, details, options); | |
case 'simple': | |
return await this.findTermsSimple(text, details, options); | |
default: | |
return [[], 0]; | |
} | |
} |
yomichan/ext/mixed/js/display.js
Lines 455 to 477 in 0cd1f8f
async setContent(type, details) { | |
const token = {}; // Unique identifier token | |
this.setContentToken = token; | |
try { | |
switch (type) { | |
case 'terms': | |
await this.setContentTerms(details.definitions, details.context, token); | |
break; | |
case 'kanji': | |
await this.setContentKanji(details.definitions, details.context, token); | |
break; | |
case 'orphaned': | |
this.setContentOrphaned(); | |
break; | |
} | |
} catch (e) { | |
this.onError(e); | |
} finally { | |
if (this.setContentToken === token) { | |
this.setContentToken = null; | |
} | |
} | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I guess it can be done in another PR later too if the amount of changes needed would otherwise explode. The variable names are also becoming more relevant when using object destructuring as I noticed in 0112dba.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll take care of it in this PR, just haven't gotten around to it yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, it's considerably more simple to do the opposite of what I said. So in the interest of minimal changes, and hopefully minimal breakage, I went that route. 0cbf427
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, tested that it still works
It's made up, added in order to allow the same API to be used without having to make the return value more complicated than a string. |
As mentioned in #399, this refactors the other audio.js source.