Import classes in the proper way to not cause runtime errors.

This commit is contained in:
László Monda
2016-03-29 01:43:52 +02:00
parent b2f5bf1d66
commit 30f735d0ac
5 changed files with 8 additions and 17 deletions

View File

@@ -1,16 +1,13 @@
/// <reference path="KeyActionNone.ts" />
/// <reference path="KeystrokeAction.ts" />
class KeyAction {
static fromJsObject(jsObject: any): KeyAction {
switch (jsObject.keyActionType) {
case KeystrokeAction.actionTypeString:
return new KeyActionNone().fromJsObject(jsObject);
case KeystrokeAction.actionTypeString:
return new KeystrokeAction().fromJsObject(jsObject);
case KeyActionNone.actionTypeString:
return new KeyActionNone().fromJsObject(jsObject);
default:
throw 'Unknown KeyAction actionType "${jsObject.actionType}"';
throw 'Invalid KeyAction.keyActionType: "${jsObject.actionType}"';
}
}
@@ -23,7 +20,7 @@ class KeyAction {
} else if (keyActionFirstByte === KeyActionNone.keyActionNoneId) {
return new KeyActionNone().fromBinary(buffer);
} else {
throw 'Unknown KeyAction first byte "${keyActionFirstByte}"';
throw 'Invalid KeyAction first byte "${keyActionFirstByte}"';
}
}
}

View File

@@ -1,6 +1,3 @@
/// <reference path="KeyAction.ts" />
/// <reference path="Serializable.ts" />
class KeyActionNone extends KeyAction implements Serializable<KeyActionNone> {
static actionTypeString = 'none';

View File

@@ -1,6 +1,3 @@
/// <reference path="KeyAction.ts" />
/// <reference path="Serializable.ts" />
class KeystrokeAction extends KeyAction implements Serializable<KeystrokeAction> {
static actionTypeString = 'keystroke';

View File

@@ -1,5 +1,3 @@
/// <reference path="UhkBuffer.ts" />
interface Serializable<T> {
fromJsObject(jsObject: any): T;
fromBinary(buffer: UhkBuffer): T;

View File

@@ -1,5 +1,8 @@
/// <reference path="Serializable.ts" />
/// <reference path="UhkBuffer.ts" />
/// <reference path="KeyAction.ts" />
/// <reference path="KeystrokeAction.ts" />
/// <reference path="KeyActionNone.ts" />
let fs = require('fs');
let writer = new UhkBuffer();
@@ -147,6 +150,5 @@ function serializeSwitchLayerAction(switchLayerAction) {
}[switchLayerAction] | switchLayerAction.toggle ? SWITCH_LAYER_TOGGLE : 0);
}
new KeystrokeAction();
serializeKeyActions(keyActions);
//serializeKeyActions(keyActions);
fs.writeFileSync('uhk-config.bin', writer.buffer);