Use references in key actions (#204)
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user