From 896edf711a33739e60bf7c3ecdac4b7a89c947c2 Mon Sep 17 00:00:00 2001 From: Aliaksandr Radzivanovich Date: Tue, 2 Apr 2024 13:51:08 +0200 Subject: [PATCH] refactor: rename functions --- packages/keybr-keyboard/lib/keyboard.test.ts | 20 +++++++++---------- packages/keybr-keyboard/lib/keyboard.ts | 6 +----- packages/keybr-keyboard/lib/keycharacters.ts | 2 +- packages/keybr-keyboard/lib/keyshape.ts | 2 +- packages/keybr-keyboard/lib/load.test.ts | 2 +- packages/keybr-keyboard/lib/stats.ts | 2 +- .../lib/LessonLoader.test.tsx | 2 +- .../keybr-lesson-loader/lib/LessonLoader.tsx | 2 +- .../keybr-textinput-events/lib/emulation.ts | 2 +- .../lib/settings/KeyboardSettings.tsx | 2 +- .../lib/profile/ResultGrouper.tsx | 2 +- 11 files changed, 20 insertions(+), 24 deletions(-) diff --git a/packages/keybr-keyboard/lib/keyboard.test.ts b/packages/keybr-keyboard/lib/keyboard.test.ts index abb88d8f..afd455b7 100644 --- a/packages/keybr-keyboard/lib/keyboard.test.ts +++ b/packages/keybr-keyboard/lib/keyboard.test.ts @@ -38,26 +38,26 @@ test("data", (t) => { const kc0x00e1 = new KeyCombo(/* á */ 0x00e1, "KeyA", None, kc0x0301); t.deepEqual( - [...keyboard.codePoints({ dead: true, shift: true, alt: true })], + [...keyboard.getCodePoints({ dead: true, shift: true, alt: true })], [ /* A */ 0x0041, /* B */ 0x0042, /* a */ 0x0061, /* b */ 0x0062, /* À */ 0x00c0, /* Á */ 0x00c1, /* à */ 0x00e0, /* á */ 0x00e1, ], ); t.deepEqual( - [...keyboard.codePoints({ dead: false, shift: true, alt: true })], + [...keyboard.getCodePoints({ dead: false, shift: true, alt: true })], [/* A */ 0x0041, /* B */ 0x0042, /* a */ 0x0061, /* b */ 0x0062], ); t.deepEqual( - [...keyboard.codePoints({ dead: false, shift: true, alt: false })], + [...keyboard.getCodePoints({ dead: false, shift: true, alt: false })], [/* A */ 0x0041, /* a */ 0x0061], ); t.deepEqual( - [...keyboard.codePoints({ dead: false, shift: false, alt: true })], + [...keyboard.getCodePoints({ dead: false, shift: false, alt: true })], [/* a */ 0x0061, /* b */ 0x0062], ); t.deepEqual( - [...keyboard.codePoints({ dead: false, shift: false, alt: false })], + [...keyboard.getCodePoints({ dead: false, shift: false, alt: false })], [/* a */ 0x0061], ); @@ -82,9 +82,9 @@ test("data", (t) => { t.is(shape1.finger, "indexRight"); t.is(shape1.hand, "right"); t.is(shape1.row, null); - t.deepEqual(keyboard.getShapesInZone("left"), [shape0]); - t.deepEqual(keyboard.getShapesInZone("right"), [shape1]); - t.deepEqual(keyboard.getShapesInZone("indexLeft"), [shape0]); - t.deepEqual(keyboard.getShapesInZone("indexRight"), [shape1]); - t.deepEqual(keyboard.getShapesInZone("home"), []); + t.deepEqual(keyboard.zones.get("left"), [shape0]); + t.deepEqual(keyboard.zones.get("right"), [shape1]); + t.deepEqual(keyboard.zones.get("indexLeft"), [shape0]); + t.deepEqual(keyboard.zones.get("indexRight"), [shape1]); + t.is(keyboard.zones.get("home"), undefined); }); diff --git a/packages/keybr-keyboard/lib/keyboard.ts b/packages/keybr-keyboard/lib/keyboard.ts index 811c2a22..fe4f9c83 100644 --- a/packages/keybr-keyboard/lib/keyboard.ts +++ b/packages/keybr-keyboard/lib/keyboard.ts @@ -78,11 +78,7 @@ export class Keyboard { return this.shapes.get(id) ?? null; } - getShapesInZone(id: ZoneId): readonly KeyShape[] { - return this.zones.get(id) ?? []; - } - - codePoints({ + getCodePoints({ dead = true, shift = true, alt = true, diff --git a/packages/keybr-keyboard/lib/keycharacters.ts b/packages/keybr-keyboard/lib/keycharacters.ts index cc3e3524..7c32c056 100644 --- a/packages/keybr-keyboard/lib/keycharacters.ts +++ b/packages/keybr-keyboard/lib/keycharacters.ts @@ -11,7 +11,7 @@ export class KeyCharacters { readonly d: CodePoint, ) {} - codePoint(modifier: KeyModifier): CodePoint { + getCodePoint(modifier: KeyModifier): CodePoint { const { a, b, c, d } = this; switch (modifier) { case KeyModifier.None: diff --git a/packages/keybr-keyboard/lib/keyshape.ts b/packages/keybr-keyboard/lib/keyshape.ts index 99940cde..2a56a7b8 100644 --- a/packages/keybr-keyboard/lib/keyshape.ts +++ b/packages/keybr-keyboard/lib/keyshape.ts @@ -82,7 +82,7 @@ export class KeyShape { this.row = selectZone(KeyShape.rowZones, this.zones); } - isZone(id: ZoneId): boolean { + inZone(id: ZoneId): boolean { return this.zones.includes(id); } } diff --git a/packages/keybr-keyboard/lib/load.test.ts b/packages/keybr-keyboard/lib/load.test.ts index db292aa7..c0e9fd1b 100644 --- a/packages/keybr-keyboard/lib/load.test.ts +++ b/packages/keybr-keyboard/lib/load.test.ts @@ -76,7 +76,7 @@ for (const layout of Layout.ALL) { for (const geometry of layout.geometries) { test(`load layout ${layout.id}/${geometry.id}`, (t) => { const keyboard = loadKeyboard(layout, geometry); - const codePoints = keyboard.codePoints({ + const codePoints = keyboard.getCodePoints({ dead: true, shift: true, alt: true, diff --git a/packages/keybr-keyboard/lib/stats.ts b/packages/keybr-keyboard/lib/stats.ts index e03301d0..9fbbea63 100644 --- a/packages/keybr-keyboard/lib/stats.ts +++ b/packages/keybr-keyboard/lib/stats.ts @@ -31,7 +31,7 @@ export function computeStats( for (const { a: x, f } of ng1) { const key = getShape(x); if (key != null) { - if (key.isZone(zone)) { + if (key.inZone(zone)) { a += f; } else { b += f; diff --git a/packages/keybr-lesson-loader/lib/LessonLoader.test.tsx b/packages/keybr-lesson-loader/lib/LessonLoader.test.tsx index 1f28d000..0908cbdc 100644 --- a/packages/keybr-lesson-loader/lib/LessonLoader.test.tsx +++ b/packages/keybr-lesson-loader/lib/LessonLoader.test.tsx @@ -19,7 +19,7 @@ test.serial("load", async (t) => { => { - const codePoints = keyboard.codePoints(); + const codePoints = keyboard.getCodePoints(); const newModel = PhoneticModel.restrict(model, codePoints); const lessonType = settings.get(lessonProps.type); const layout = settings.get(keyboardProps.layout); diff --git a/packages/keybr-textinput-events/lib/emulation.ts b/packages/keybr-textinput-events/lib/emulation.ts index ca1fc184..52504ae8 100644 --- a/packages/keybr-textinput-events/lib/emulation.ts +++ b/packages/keybr-textinput-events/lib/emulation.ts @@ -73,7 +73,7 @@ function remap( const characters = layout.getCharacters(code); let codePoint = 0x0000; if (characters != null) { - codePoint = characters.codePoint(KeyModifier.from({ shiftKey, altKey })); + codePoint = characters.getCodePoint(KeyModifier.from({ shiftKey, altKey })); if (codePoint > 0x0000) { key = String.fromCodePoint(codePoint); } diff --git a/packages/page-practice/lib/settings/KeyboardSettings.tsx b/packages/page-practice/lib/settings/KeyboardSettings.tsx index 81bd7f95..d28d5c31 100644 --- a/packages/page-practice/lib/settings/KeyboardSettings.tsx +++ b/packages/page-practice/lib/settings/KeyboardSettings.tsx @@ -154,7 +154,7 @@ function PointersPreview(): ReactNode { const [index, setIndex] = useState(0); const suffix = useMemo(() => { setIndex(0); - const codePoints = keyboard.codePoints(); + const codePoints = keyboard.getCodePoints(); return getExampleText(keyboard.layout.language).filter((codePoint) => codePoints.has(codePoint), ); diff --git a/packages/page-profile/lib/profile/ResultGrouper.tsx b/packages/page-profile/lib/profile/ResultGrouper.tsx index a5f5c9d7..e9e4b295 100644 --- a/packages/page-profile/lib/profile/ResultGrouper.tsx +++ b/packages/page-profile/lib/profile/ResultGrouper.tsx @@ -111,7 +111,7 @@ export function ResultGrouper({ case "letters": return children( newKeyStatsMap( - Letter.restrict(letters, keyboard.codePoints()), + Letter.restrict(letters, keyboard.getCodePoints()), group, ), );