aboutsummaryrefslogtreecommitdiff
path: root/src/shared/settings
diff options
context:
space:
mode:
authorShin'ya UEOKA <ueokande@i-beam.org>2019-10-04 04:01:35 +0000
committerShin'ya UEOKA <ueokande@i-beam.org>2019-10-06 12:58:59 +0000
commit410ffbb0376b9399928ef8d4dd13079bfb120e14 (patch)
treee408870fb867c7affb04c9b0130463df24e9f097 /src/shared/settings
parentb496cea5827165bd23a503231f94f708a976cad4 (diff)
Make Keymap class
Diffstat (limited to 'src/shared/settings')
-rw-r--r--src/shared/settings/Keymaps.ts37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/shared/settings/Keymaps.ts b/src/shared/settings/Keymaps.ts
new file mode 100644
index 0000000..a5558b0
--- /dev/null
+++ b/src/shared/settings/Keymaps.ts
@@ -0,0 +1,37 @@
+import * as operations from '../operations';
+
+export type KeymapsJSON = { [key: string]: operations.Operation };
+
+export default class Keymaps {
+ constructor(
+ private readonly data: KeymapsJSON,
+ ) {
+ }
+
+ static fromJSON(json: any): Keymaps {
+ if (typeof json !== 'object' || json === null) {
+ throw new TypeError('invalid keymaps type: ' + JSON.stringify(json));
+ }
+
+ let data: KeymapsJSON = {};
+ for (let key of Object.keys(json)) {
+ data[key] = operations.valueOf(json[key]);
+ }
+ return new Keymaps(data);
+ }
+
+ combine(other: Keymaps): Keymaps {
+ return new Keymaps({
+ ...this.data,
+ ...other.data,
+ });
+ }
+
+ toJSON(): KeymapsJSON {
+ return this.data;
+ }
+
+ entries(): [string, operations.Operation][] {
+ return Object.entries(this.data);
+ }
+}