import { SerializedObjectType } from "../serialization/SerializedTypes" ; import { RTTI } from "./RTTI" ; import { ISerializerInternal } from "../serialization/ISerializer" ; import { IFactoryInternal } from "../serialization/IFactory" ; import { ObjectProps } from "./Types" ; export interface SerializedProperty { typeName ? : string ; data : any ; } export interface SerializedObject { typeName ? : string ; version : number ; properties : { [ propertyName ] : SerializedProperty ; } ; } export class SerializableObject { isA < T > ( type ) { return RTTI . isObjectOfType ( this . constructor . name , type . name ) ; } copy ( ) { let copy = IFactoryInternal . instance . createObject ( this . constructor . name ) as SerializableObject ; copy . deserialize ( this . serialize ( ) ) ; return copy ; } destroy ( ) { } setProperty ( name , value ) { this [ name ] = value ; } serialize ( ) { return ISerializerInternal . instance . serializeObject ( this ) ; } deserialize ( json ) { ISerializerInternal . instance . deserializeObject ( this , json as SerializedObject ) ; return this ; } upgrade ( json , previousVersion ) { return json ; } setState < T > ( props ) { Object . entries ( props ) . forEach ( ( [ key , value ] ) => { Object . assign ( this , { [ key ] : value } ) ; } ) ; } }