From 0e076d53897311e9988f41515e2bdeecb4100517 Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Fri, 10 Jul 2026 16:55:06 +0200 Subject: [PATCH] chore(web): declare scope for stubAndKeyboardCache members Also remove redundant `fetchKeyboardForStub` function, as it had only a single use (and was not unit tested directly). Test-bot: skip --- .../keyboard-storage/stubAndKeyboardCache.ts | 35 +++++++++---------- web/src/engine/src/main/contextManagerBase.ts | 2 +- .../stubAndKeyboardCache.tests.js | 2 +- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/web/src/engine/src/keyboard-storage/stubAndKeyboardCache.ts b/web/src/engine/src/keyboard-storage/stubAndKeyboardCache.ts index 8564e80ef4..9a35594712 100644 --- a/web/src/engine/src/keyboard-storage/stubAndKeyboardCache.ts +++ b/web/src/engine/src/keyboard-storage/stubAndKeyboardCache.ts @@ -1,3 +1,6 @@ +/* + * Keyman is copyright (C) SIL Global. MIT License. + */ import { Keyboard, JSKeyboard, KeyboardLoaderBase as KeyboardLoader } from "keyman/engine/keyboard"; import { EventEmitter } from "eventemitter3"; @@ -48,14 +51,14 @@ export class StubAndKeyboardCache extends EventEmitter { this.keyboardLoader = keyboardLoader; } - shutdown(): void { + public shutdown(): void { } - getKeyboardForStub(stub: KeyboardStub): Keyboard { + public getKeyboardForStub(stub: KeyboardStub): Keyboard { return stub ? this.getKeyboard(stub.KI) : null; } - getKeyboard(keyboardID: string): Keyboard { + public getKeyboard(keyboardID: string): Keyboard { if(!keyboardID) { return null; } @@ -68,7 +71,7 @@ export class StubAndKeyboardCache extends EventEmitter { return entry instanceof Promise ? null : entry; } - get defaultStub(): KeyboardStub { + public get defaultStub(): KeyboardStub { /* See the following two StackOverflow links: * - https://stackoverflow.com/a/23202095 * - https://stackoverflow.com/a/5525820 @@ -111,18 +114,14 @@ export class StubAndKeyboardCache extends EventEmitter { } } - addKeyboard(keyboard: Keyboard) { + public addKeyboard(keyboard: Keyboard): void { const keyboardID = toPrefixedKeyboardId(keyboard.id); this.keyboardTable[keyboardID] = keyboard; this.emit('keyboardadded', keyboard); } - fetchKeyboardForStub(stub: KeyboardStub) : Promise { - return this.fetchKeyboard(stub.KI); - } - - isFetchingKeyboard(keyboardID: string): boolean { + public isFetchingKeyboard(keyboardID: string): boolean { if(!keyboardID) { throw new Error("Keyboard ID must be specified"); } @@ -133,7 +132,7 @@ export class StubAndKeyboardCache extends EventEmitter { return cachedEntry instanceof Promise; } - fetchKeyboard(keyboardID: string): Promise { + public fetchKeyboard(keyboardID: string): Promise { if(!keyboardID) { throw new Error("Keyboard ID must be specified"); } @@ -178,7 +177,7 @@ export class StubAndKeyboardCache extends EventEmitter { return promise; } - addStub(stub: KeyboardStub) { + public addStub(stub: KeyboardStub): void { const keyboardID = toPrefixedKeyboardId(stub.KI); const stubTable = this.stubSetTable[keyboardID] = this.stubSetTable[keyboardID] ?? {}; stubTable[stub.KLC] = stub; @@ -186,13 +185,13 @@ export class StubAndKeyboardCache extends EventEmitter { this.emit('stubadded', stub); } - findMatchingStub(stub: KeyboardStub) { + public findMatchingStub(stub: KeyboardStub) { return this.getStub(stub.KI, stub.KLC); } - getStub(keyboardID: string, languageID: string): KeyboardStub; - getStub(keyboard: Keyboard, languageID?: string): KeyboardStub; - getStub(arg0: string | Keyboard, arg1?: string): KeyboardStub { + public getStub(keyboardID: string, languageID: string): KeyboardStub; + public getStub(keyboard: Keyboard, languageID?: string): KeyboardStub; + public getStub(arg0: string | Keyboard, arg1?: string): KeyboardStub { let keyboardID: string; const languageID = arg1 || '---'; @@ -227,7 +226,7 @@ export class StubAndKeyboardCache extends EventEmitter { * @param purge If `true`, will also purge the `Keyboard` instance itself from the cache. * If `false`, only forgets the metadata (stubs). */ - forgetKeyboard(keyboard: string | Keyboard, purge: boolean = false) { + public forgetKeyboard(keyboard: string | Keyboard, purge: boolean = false): void { const id: string = (keyboard instanceof JSKeyboard) ? keyboard.id : toPrefixedKeyboardId(keyboard as string); if(this.stubSetTable[id]) { @@ -239,7 +238,7 @@ export class StubAndKeyboardCache extends EventEmitter { } } - getStubList(): KeyboardStub[] { + public getStubList(): KeyboardStub[] { const arr: KeyboardStub[] = []; const kbdIds = Object.keys(this.stubSetTable); diff --git a/web/src/engine/src/main/contextManagerBase.ts b/web/src/engine/src/main/contextManagerBase.ts index 3138bd084c..9437dafc1b 100644 --- a/web/src/engine/src/main/contextManagerBase.ts +++ b/web/src/engine/src/main/contextManagerBase.ts @@ -365,7 +365,7 @@ export abstract class ContextManagerBase const completionPromise = new ManagedPromise(); this.emit('keyboardasyncload', requestedStub, completionPromise.corePromise); - const keyboardPromise = this.keyboardCache.fetchKeyboardForStub(requestedStub); + const keyboardPromise = this.keyboardCache.fetchKeyboard(requestedStub.KI); const timeoutPromise = new Promise((resolve, reject) => { const timeoutMsg = `Sorry, the ${requestedStub.name} keyboard for ${requestedStub.langName} is not currently available.`; window.setTimeout(() => reject(new Error(timeoutMsg)), ContextManagerBase.TIMEOUT_THRESHOLD); diff --git a/web/src/test/auto/headless/engine/keyboard-storage/stubAndKeyboardCache.tests.js b/web/src/test/auto/headless/engine/keyboard-storage/stubAndKeyboardCache.tests.js index 106c76b202..082d40c247 100644 --- a/web/src/test/auto/headless/engine/keyboard-storage/stubAndKeyboardCache.tests.js +++ b/web/src/test/auto/headless/engine/keyboard-storage/stubAndKeyboardCache.tests.js @@ -165,7 +165,7 @@ describe('StubAndKeyboardCache', function () { cache.addStub(bad_stub); try { - cache.fetchKeyboardForStub(bad_stub); + cache.fetchKeyboard(bad_stub.KI); assert.fail(); } catch(err) { assert.isTrue(err instanceof Error);