refactor(web): clarify function scope and update some function comments - #16532
Open
ermshiperete wants to merge 2 commits into
Open
refactor(web): clarify function scope and update some function comments#16532ermshiperete wants to merge 2 commits into
ermshiperete wants to merge 2 commits into
Conversation
User Test ResultsTest specification and instructions User tests are not required Test Artifacts
|
Build-bot: skip build:web Test-bot: skip
ermshiperete
marked this pull request as ready for review
September 4, 2026 20:34
mcdurdin
requested changes
Sep 5, 2026
Comment on lines
324
to
326
| } else { | ||
| languageCode == ''; | ||
| languageCode = ''; | ||
| } |
Member
There was a problem hiding this comment.
Good catch. However, if !keyboardId, we always (line 333) return quickly anyway:
return {
keyboard: Promise.resolve(null),
metadata: null
}So it has no impact because it was never used...
It'd be better to move the parameter nullish check to the top of the function and simplify the logic:
protected prepareKeyboardForActivation(
keyboardId: string,
languageCode?: string
): {keyboard: Promise<Keyboard>, metadata: KeyboardStub} {
if(!keyboardId) {
return {
keyboard: Promise.resolve(null),
metadata: null
}
}
// Set default language code
languageCode ||= '';
// Check that the saved keyboard is currently registered
const requestedStub: KeyboardStub = this.keyboardCache.getStub(keyboardId, languageCode);
if(!requestedStub) {
const availableStubList = this.keyboardCache.getStubList().map(stub => `${stub.KI}@${stub.KLC}`);
throw new Error(`No matching stub has been registered for keyboard ${keyboardId}. Available stubs: ${JSON.stringify(availableStubList)}`);
}
// Check if current keyboard matches requested keyboard, but not (necessarily) stub
if (keyboardId === this.activeKeyboard?.metadata?.id) {
const {keyboard} = this.activeKeyboard;
// In this case, the keyboard is loaded; just update the stub.
return {
keyboard: Promise.resolve(keyboard),
metadata: requestedStub
};
}Secondary question, why would we ever call prepareKeyboardForActivation with a nullish keyboardId? That smells buggy in itself.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Build-bot: skip build:web
Test-bot: skip