Skip to content

Commit b94661a

Browse files
committed
refactor(web): rename VariableStoreVariableStores
Addresses code review comments. Test-bot: skip
1 parent 01bee77 commit b94661a

File tree

7 files changed

+34
-34
lines changed

7 files changed

+34
-34
lines changed

web/src/engine/src/js-processor/jsKeyboardInterface.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
type Deadkey,
2222
type KeyEvent,
2323
type TextStore,
24-
VariableStore,
24+
VariableStores,
2525
VariableStoreSerializer,
2626
} from "keyman/engine/keyboard";
2727
import { PlatformSystemStore } from './platformSystemStore.js';
@@ -963,7 +963,7 @@ export class JSKeyboardInterface extends KeyboardHarness {
963963
}
964964

965965
// And the lookup under that entry looks for the value under the store name, again.
966-
const valueObj: VariableStore = {};
966+
const valueObj: VariableStores = {};
967967
valueObj[storeName] = optValue;
968968

969969
// Null-check in case of invocation during unit-test
@@ -1102,7 +1102,7 @@ export class JSKeyboardInterface extends KeyboardHarness {
11021102
* @param stores A dictionary of stores which should be found in the
11031103
* keyboard
11041104
*/
1105-
applyVariableStores(stores: VariableStore): void {
1105+
applyVariableStores(stores: VariableStores): void {
11061106
this.activeKeyboard.variableStores = stores;
11071107
}
11081108

web/src/engine/src/keyboard/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export { EmulationKeystrokes, LogMessages, DefaultRules } from "./defaultRules.j
3030
export { type KeyDistribution, KeyEventSpec, KeyEvent } from "./keyEvent.js";
3131
export { KeyMapping } from "./keyMapping.js";
3232
export { type SystemStoreMutationHandler, MutableSystemStore, SystemStore, SystemStoreIDs, type SystemStoreDictionary } from "./systemStore.js";
33-
export { type VariableStore, VariableStoreSerializer } from "./variableStore.js";
33+
export { type VariableStores, VariableStoreSerializer } from "./variableStores.js";
3434

3535
export { DOMKeyboardLoader } from './keyboards/loaders/domKeyboardLoader.js';
3636
export { SyntheticTextStore } from "./syntheticTextStore.js";

web/src/engine/src/keyboard/keyboards/jsKeyboard.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ActiveKey, ActiveLayout, ActiveSubKey } from "./activeLayout.js";
44
import { KeyEvent } from "../keyEvent.js";
55
import { type TextStore } from "../textStore.js";
66
import { KeymanWebKeyboard, ModifierKeyConstants, TouchLayout } from "@keymanapp/common-types";
7-
import { VariableStore } from "../variableStore.js";
7+
import { VariableStores } from "../variableStores.js";
88

99
import ComplexKeyboardStore = KeymanWebKeyboard.ComplexKeyboardStore;
1010
import KeyboardObject = KeymanWebKeyboard.KeyboardObject;
@@ -120,11 +120,11 @@ export class JSKeyboard {
120120
*
121121
* @returns an object with each property referencing a variable store
122122
*/
123-
get variableStores(): VariableStore {
123+
get variableStores(): VariableStores {
124124
const storeNames = this.scriptObject['KVS'];
125-
let values: VariableStore = {};
125+
const values: VariableStores = {};
126126
if(Array.isArray(storeNames)) {
127-
for(let store of storeNames) {
127+
for(const store of storeNames) {
128128
values[store] = this.scriptObject[store];
129129
}
130130
}
@@ -139,10 +139,10 @@ export class JSKeyboard {
139139
*
140140
* @param values name-value pairs for each store value
141141
*/
142-
set variableStores(values: VariableStore) {
142+
set variableStores(values: VariableStores) {
143143
const storeNames = this.scriptObject['KVS'];
144144
if(Array.isArray(storeNames)) {
145-
for(let store of storeNames) {
145+
for(const store of storeNames) {
146146
// If the value is not present in the cache, don't overwrite it;
147147
// while this is not used in initial implementation, we could use
148148
// it in future to update a single variable store value rather than

web/src/engine/src/keyboard/keyboards/processorAction.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44
import { LexicalModelTypes } from '@keymanapp/common-types';
55
import { Transcription } from './transcription.js';
6-
import { VariableStore } from '../variableStore.js';
6+
import { VariableStores } from '../variableStores.js';
77
import { SystemStoreDictionary } from '../systemStore.js';
88

99
/**
@@ -29,12 +29,12 @@ export class ProcessorAction {
2929
/**
3030
* A set of variable stores with save requests triggered by the matched keyboard rule
3131
*/
32-
saveStore: {[name: string]: VariableStore} = {};
32+
saveStore: {[name: string]: VariableStores} = {};
3333

3434
/**
3535
* A set of variable stores with possible changes to be applied during finalization.
3636
*/
37-
variableStores: VariableStore = {};
37+
variableStores: VariableStores = {};
3838

3939
/**
4040
* Denotes a non-output default behavior; this should be evaluated later, against the true keystroke.

web/src/engine/src/keyboard/variableStore.ts renamed to web/src/engine/src/keyboard/variableStores.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
* Definitions for variable stores (see kmn reference)
55
*/
66

7-
export type VariableStore = { [name: string]: string; };
7+
export type VariableStores = { [name: string]: string; };
88

99
export interface VariableStoreSerializer {
10-
loadStore(keyboardID: string, storeName: string): VariableStore;
11-
saveStore(keyboardID: string, storeName: string, storeMap: VariableStore): void;
12-
findStores(keyboardID: string): VariableStore[];
10+
loadStore(keyboardID: string, storeName: string): VariableStores;
11+
saveStore(keyboardID: string, storeName: string, storeMap: VariableStores): void;
12+
findStores(keyboardID: string): VariableStores[];
1313
}

web/src/engine/src/main/variableStoreCookieSerializer.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { VariableStore, VariableStoreSerializer } from 'keyman/engine/keyboard';
1+
import { VariableStores, VariableStoreSerializer } from 'keyman/engine/keyboard';
22
import { CookieSerializer } from "keyman/engine/dom-utils";
33

44
// While there's little reason we couldn't store all of a keyboard's store values within
@@ -14,13 +14,13 @@ export class VariableStoreCookieSerializer implements VariableStoreSerializer {
1414
return `KeymanWeb_${keyboardID}_Option_${storeName}`;
1515
}
1616

17-
public loadStore(keyboardID: string, storeName: string): VariableStore {
18-
const storeCookieSerializer = new CookieSerializer<VariableStore>(this.getStoreCookieName(keyboardID, storeName));
17+
public loadStore(keyboardID: string, storeName: string): VariableStores {
18+
const storeCookieSerializer = new CookieSerializer<VariableStores>(this.getStoreCookieName(keyboardID, storeName));
1919
return storeCookieSerializer.load(decodeURIComponent);
2020
}
2121

22-
public saveStore(keyboardID: string, storeName: string, storeMap: VariableStore) {
23-
const storeCookieSerializer = new CookieSerializer<VariableStore>(this.getStoreCookieName(keyboardID, storeName));
22+
public saveStore(keyboardID: string, storeName: string, storeMap: VariableStores) {
23+
const storeCookieSerializer = new CookieSerializer<VariableStores>(this.getStoreCookieName(keyboardID, storeName));
2424
storeCookieSerializer.save(storeMap, encodeURIComponent);
2525
}
2626

@@ -29,11 +29,11 @@ export class VariableStoreCookieSerializer implements VariableStoreSerializer {
2929
*
3030
* @param {string} keyboardID The keyboard ID whose variable stores are to be found.
3131
*
32-
* @returns An array of VariableStore objects found for the keyboard.
32+
* @returns An array of VariableStores objects found for the keyboard.
3333
*/
34-
public findStores(keyboardID: string): VariableStore[] {
34+
public findStores(keyboardID: string): VariableStores[] {
3535
const pattern = new RegExp(`^${this.getStoreCookieName(keyboardID, '')}`);
36-
const matching = CookieSerializer.loadAllMatching<VariableStore>(pattern, decodeURIComponent);
36+
const matching = CookieSerializer.loadAllMatching<VariableStores>(pattern, decodeURIComponent);
3737
return matching.map(m => m.value);
3838
}
3939
}

web/src/test/auto/dom/cases/main/variableStoreCookieSerializer.tests.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Keyman is copyright (C) SIL Global. MIT License.
33
*/
44
import { assert } from 'chai';
5-
import { VariableStore } from 'keyman/engine/keyboard';
5+
import { VariableStores } from 'keyman/engine/keyboard';
66
import { VariableStoreCookieSerializer } from 'keyman/engine/main';
77

88
describe('VariableStoreCookieSerializer', () => {
@@ -18,7 +18,7 @@ describe('VariableStoreCookieSerializer', () => {
1818
it('should save and load a simple store with string values', () => {
1919
// Arrange
2020
const serializer = new VariableStoreCookieSerializer();
21-
const storeData: VariableStore = {
21+
const storeData: VariableStores = {
2222
option1: 'value1',
2323
option2: 'value2',
2424
option3: 'value3'
@@ -35,7 +35,7 @@ describe('VariableStoreCookieSerializer', () => {
3535
it('should save and load a store with empty values', () => {
3636
// Arrange
3737
const serializer = new VariableStoreCookieSerializer();
38-
const storeData: VariableStore = {
38+
const storeData: VariableStores = {
3939
option1: '',
4040
option2: 'value',
4141
option3: ''
@@ -52,7 +52,7 @@ describe('VariableStoreCookieSerializer', () => {
5252
it('should save and load a store with special characters', () => {
5353
// Arrange
5454
const serializer = new VariableStoreCookieSerializer();
55-
const storeData: VariableStore = {
55+
const storeData: VariableStores = {
5656
encoded: 'value:with;special&chars=',
5757
emoji: '⭐'
5858
};
@@ -68,8 +68,8 @@ describe('VariableStoreCookieSerializer', () => {
6868
it('should handle multiple stores for the same keyboard independently', () => {
6969
// Arrange
7070
const serializer = new VariableStoreCookieSerializer();
71-
const store1Data: VariableStore = { option: 'store1value' };
72-
const store2Data: VariableStore = { option: 'store2value' };
71+
const store1Data: VariableStores = { option: 'store1value' };
72+
const store2Data: VariableStores = { option: 'store2value' };
7373

7474
// Act
7575
serializer.saveStore(keyboardID, 'store1', store1Data);
@@ -104,7 +104,7 @@ describe('VariableStoreCookieSerializer', () => {
104104
// Arrange
105105
const serializer = new VariableStoreCookieSerializer();
106106
const keyboardID = 'test-keyboard';
107-
const expected: VariableStore[] = [];
107+
const expected: VariableStores[] = [];
108108

109109
// Act
110110
const result = serializer.findStores(keyboardID);
@@ -118,13 +118,13 @@ describe('VariableStoreCookieSerializer', () => {
118118
it('should return store for keyboard', () => {
119119
// Arrange
120120
const serializer = new VariableStoreCookieSerializer();
121-
const storeData1: VariableStore = {
121+
const storeData1: VariableStores = {
122122
option1: 'value1',
123123
option2: 'value2',
124124
option3: 'value3'
125125
};
126126
serializer.saveStore('test-keyboard', 'storeName', storeData1);
127-
const storeData2: VariableStore = {
127+
const storeData2: VariableStores = {
128128
settingA: 'A',
129129
settingB: 'B'
130130
};

0 commit comments

Comments
 (0)