SerializableModel.ts
Usage
A serializable and deserializable base model written in Typescript. Use it as follows:
import SerializableModel from 'serializable-model';
export default class ChildModel extends SerializableModel {
private name;
getName():string {
return this.name;
}
setName(value:string) {
this.name = value;
}
}
Instantiation
You then can instantiate via one of the following methods:
let model = new ChildModel();
model.setName('karl');
console.log(model.getName());
Deserialization
let model = ChildModel.fromObject({ name: 'karl' });
console.log(model.getName());
which is basically the same as:
let model = new ChildModel();
model.deserialize{ name: 'karl' });
console.log(model.getName());
Serialization
let obj = model.serialize();
console.log(obj.name);