From 410ffbb0376b9399928ef8d4dd13079bfb120e14 Mon Sep 17 00:00:00 2001 From: Shin'ya UEOKA <ueokande@i-beam.org> Date: Fri, 4 Oct 2019 04:01:35 +0000 Subject: Make Keymap class --- src/content/client/SettingClient.ts | 4 ++-- src/content/usecases/KeymapUseCase.ts | 21 ++++++++------------- 2 files changed, 10 insertions(+), 15 deletions(-) (limited to 'src/content') diff --git a/src/content/client/SettingClient.ts b/src/content/client/SettingClient.ts index 0850f11..a7cd1ee 100644 --- a/src/content/client/SettingClient.ts +++ b/src/content/client/SettingClient.ts @@ -1,4 +1,4 @@ -import Settings from '../../shared/Settings'; +import Settings, { valueOf } from '../../shared/Settings'; import * as messages from '../../shared/messages'; export default interface SettingClient { @@ -10,6 +10,6 @@ export class SettingClientImpl { let settings = await browser.runtime.sendMessage({ type: messages.SETTINGS_QUERY, }); - return settings as Settings; + return valueOf(settings); } } diff --git a/src/content/usecases/KeymapUseCase.ts b/src/content/usecases/KeymapUseCase.ts index 0f654c8..62cd04c 100644 --- a/src/content/usecases/KeymapUseCase.ts +++ b/src/content/usecases/KeymapUseCase.ts @@ -3,16 +3,16 @@ import KeymapRepository from '../repositories/KeymapRepository'; import SettingRepository from '../repositories/SettingRepository'; import AddonEnabledRepository from '../repositories/AddonEnabledRepository'; import * as operations from '../../shared/operations'; -import { Keymaps } from '../../shared/Settings'; import Key from '../domains/Key'; import KeySequence from '../domains/KeySequence'; +import Keymaps from '../../shared/settings/Keymaps'; type KeymapEntityMap = Map<KeySequence, operations.Operation>; -const reservedKeymaps: Keymaps = { +const reservedKeymaps = Keymaps.fromJSON({ '<Esc>': { type: operations.CANCEL }, '<C-[>': { type: operations.CANCEL }, -}; +}); @injectable() export default class KeymapUseCase { @@ -65,16 +65,11 @@ export default class KeymapUseCase { } private keymapEntityMap(): KeymapEntityMap { - let keymaps = { - ...this.settingRepository.get().keymaps, - ...reservedKeymaps, - }; - let entries = Object.entries(keymaps).map((entry) => { - return [ - KeySequence.fromMapKeys(entry[0]), - entry[1], - ]; - }) as [KeySequence, operations.Operation][]; + let keymaps = this.settingRepository.get().keymaps.combine(reservedKeymaps); + let entries = keymaps.entries().map(entry => [ + KeySequence.fromMapKeys(entry[0]), + entry[1], + ]) as [KeySequence, operations.Operation][]; return new Map<KeySequence, operations.Operation>(entries); } } -- cgit v1.2.3