Use references in key actions (#204)

This commit is contained in:
József Farkas
2016-12-13 23:09:39 +01:00
committed by GitHub
parent 3380a9d514
commit e48fdea89d
33 changed files with 266 additions and 255 deletions

View File

@@ -8,33 +8,12 @@ export abstract class Serializable<T> {
private static maxDisplayedJsonLength = 160;
private static enableDump = false;
fromJsObject(jsObject: any): T {
this.dump(`${this.getIndentation()}${this.constructor.name}.fromJsObject: ` +
`${this.strintifyJsObject(jsObject)}\n`);
Serializable.depth++;
let value = this._fromJsObject(jsObject);
Serializable.depth--;
this.dump(`${this.getIndentation()}=> ${value}\n`);
return value;
}
fromBinary(buffer: UhkBuffer): T {
this.dump(`\n${this.getIndentation()}${this.constructor.name}.fromBinary: [`);
Serializable.depth++;
buffer.enableDump = Serializable.enableDump;
let value = this._fromBinary(buffer);
buffer.enableDump = false;
Serializable.depth--;
this.dump(`]\n${this.getIndentation()}=> ${value}`);
return value;
}
toJsObject(): any {
toJsonObject(): any {
this.dump(`${this.getIndentation()}${this.constructor.name}.toJsObject: ${this}\n`);
Serializable.depth++;
let value = this._toJsObject();
let value = this._toJsonObject();
Serializable.depth--;
this.dump(`${this.getIndentation()}=> ${this.strintifyJsObject(value)}\n`);
this.dump(`${this.getIndentation()}=> ${this.stringifyJsonObject(value)}\n`);
return value;
}
@@ -50,9 +29,7 @@ export abstract class Serializable<T> {
return value;
}
abstract _fromJsObject(jsObject: any): T;
abstract _fromBinary(buffer: UhkBuffer): T;
abstract _toJsObject(): any;
abstract _toJsonObject(): any;
abstract _toBinary(buffer: UhkBuffer): void;
private dump(value: any) {
@@ -65,8 +42,8 @@ export abstract class Serializable<T> {
return new Array(Serializable.depth + 1).join(' ');
}
private strintifyJsObject(jsObject: any): string {
let json = JSON.stringify(jsObject);
private stringifyJsonObject(jsonObject: any): string {
let json = JSON.stringify(jsonObject);
return json.length > Serializable.maxDisplayedJsonLength
? json.substr(0, Serializable.maxDisplayedJsonLength) + '...'
: json;