Make Serializable a generic. Make fromJson() and fromBinary() return the generic type.

This commit is contained in:
László Monda
2016-03-29 00:17:11 +02:00
parent 924234cea8
commit 0aeec88cb5
4 changed files with 21 additions and 24 deletions

View File

@@ -6,30 +6,22 @@ class KeyAction {
static fromJsObject(jsObject: any): KeyAction {
switch (jsObject.keyActionType) {
case KeystrokeAction.actionTypeString:
let keyActionNone = new KeyActionNone();
keyActionNone.fromJsObject(jsObject);
return keyActionNone;
return new KeyActionNone().fromJsObject(jsObject);
case KeystrokeAction.actionTypeString:
let keystrokeAction = new KeystrokeAction();
keystrokeAction.fromJsObject(jsObject);
return keystrokeAction;
return new KeystrokeAction().fromJsObject(jsObject);
default:
throw 'Unknown KeyAction actionType "${jsObject.actionType}"';
}
}
static fromBinary(buffer: UhkBuffer) {
static fromBinary(buffer: UhkBuffer): KeyAction {
let keyActionFirstByte = buffer.readUInt8();
buffer.backtrack();
if (KeystrokeAction.isScancodeValid(keyActionFirstByte)) {
let keystrokeAction = new KeystrokeAction();
keystrokeAction.fromBinary(buffer);
return keystrokeAction;
return new KeystrokeAction().fromBinary(buffer);
} else if (keyActionFirstByte === KeyActionNone.keyActionNoneId) {
let keyActionNone = new KeyActionNone();
keyActionNone.fromBinary(buffer);
return keyActionNone;
return new KeyActionNone().fromBinary(buffer);
} else {
throw 'Unknown KeyAction first byte "${keyActionFirstByte}"';
}