Add assertion decorations for various numeric types.

This commit is contained in:
László Monda
2016-04-08 22:26:00 +02:00
parent 49d0ad270b
commit f6eb819cfe
9 changed files with 48 additions and 87 deletions

View File

@@ -14,24 +14,11 @@ enum LongPressAction {
class DualRoleKeystrokeAction extends KeyAction {
public scancode;
@assertUInt8
scancode: number;
private _longPressAction: LongPressAction;
get longPressAction(): number {
return this._longPressAction;
}
set longPressAction(value) {
if (!this.isDualRoleKeystrokeActionValid(value)) {
throw `Invalid DualRoleKeystrokeAction.longPressAction: ${value}`;
}
this._longPressAction = value;
}
isDualRoleKeystrokeActionValid(keyActionIdParam): boolean {
return LongPressAction[keyActionIdParam] !== undefined;
}
@assertEnum(LongPressAction)
private longPressAction: LongPressAction;
_fromJsObject(jsObject: any): DualRoleKeystrokeAction {
this.assertKeyActionType(jsObject, KeyActionType.DualRoleKeystrokeAction, 'DualRoleKeystrokeAction');

View File

@@ -1,14 +1,7 @@
class KeystrokeAction extends KeyAction {
private _scancode: number;
get scancode(): number {
return this._scancode;
}
set scancode(value) {
this._scancode = value;
}
@assertUInt8
scancode: number;
_fromJsObject(jsObject: any): KeystrokeAction {
this.assertKeyActionType(jsObject, KeyActionType.KeystrokeAction, 'KeystrokeAction');

View File

@@ -1,5 +1,6 @@
class KeystrokeModifiersAction extends KeyAction {
@assertUInt8
modifierMask: number;
_fromJsObject(jsObject: any): KeystrokeModifiersAction {

View File

@@ -1,16 +1,10 @@
class KeystrokeWithModifiersAction extends KeyAction {
@assertUInt8
modifierMask: number;
private _scancode: number;
get scancode(): number {
return this._scancode;
}
set scancode(value) {
this._scancode = value;
}
@assertUInt8
scancode: number;
_fromJsObject(jsObject: any): KeystrokeWithModifiersAction {
this.assertKeyActionType(

View File

@@ -15,22 +15,9 @@ enum MouseActionParam {
}
class MouseAction extends KeyAction {
private _mouseAction: MouseActionParam;
get mouseAction(): MouseActionParam {
return this._mouseAction;
}
set mouseAction(mouseAction) {
// if (!this.isMouseActionValid(mouseAction)) {
// throw `Invalid MouseAction.mouseAction: ${mouseAction}`;
// }
this._mouseAction = mouseAction;
}
// isMouseActionValid(keyActionParam): boolean {
// return MouseActionParam[<string>keyActionParam] !== undefined;
// }
@assertUInt8
mouseAction: MouseActionParam;
_fromJsObject(jsObject: any): MouseAction {
this.assertKeyActionType(jsObject, KeyActionType.MouseAction, 'MouseAction');
@@ -40,12 +27,7 @@ class MouseAction extends KeyAction {
_fromBinary(buffer: UhkBuffer): MouseAction {
this.readAndAssertKeyActionId(buffer, KeyActionId.MouseAction, 'MouseAction');
this.mouseAction = buffer.readUInt8();
// if (!this.isMouseActionValid(this.mouseAction)) {
// throw `Invalid MouseAction.param: ${this.mouseAction}`;
// }
return this;
}

View File

@@ -1,14 +1,7 @@
class PlayMacroAction extends KeyAction {
private _macroId: number;
get macroId(): number {
return this._macroId;
}
set macroId(value) {
this._macroId = value;
}
@assertUInt8
macroId: number;
_fromJsObject(jsObject: any): PlayMacroAction {
this.assertKeyActionType(jsObject, KeyActionType.PlayMacroAction, 'PlayMacroAction');

View File

@@ -1,14 +1,7 @@
class SwitchKeymapAction extends KeyAction {
private _keymapId: number;
get keymapId(): number {
return this._keymapId;
}
set keymapId(value) {
this._keymapId = value;
}
@assertUInt8
keymapId: number;
_fromJsObject(jsObject: any): SwitchKeymapAction {
this.assertKeyActionType(jsObject, KeyActionType.SwitchKeymapAction, 'SwitchKeymapAction');

View File

@@ -12,18 +12,7 @@ class SwitchLayerAction extends KeyAction {
@assertEnum(Layer)
private layer: Layer;
/*
get layer(): number {
return this._layer;
}
set layer(value) {
if (!TypeChecker.isUInt8Valid(value)) {
throw 'Invalid SwitchLayerAction.layerId: ${value}';
}
this._layer = value;
}
*/
getToggleFlag() {
return this.isLayerToggleable ? SwitchLayerAction.toggleFlag : 0;
}