Last active
June 3, 2019 01:48
-
-
Save codeBelt/b173c573ef1a8b1581ae56c4719e2657 to your computer and use it in GitHub Desktop.
For Medium Article: https://medium.com/swlh/protect-your-javascript-applications-from-api-data-401a73c7c80b
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import LocationModel from './LocationModel'; | |
import CarModel from './CarModel'; | |
import {BaseModel} from 'sjs-base-model'; | |
class PersonModel extends BaseModel { | |
public readonly firstName: string = ''; | |
public readonly lastName: string = ''; | |
public readonly age: string = 0; | |
public readonly address: LocationModel = LocationModel as any; | |
public readonly cars: CarModel[] = [CarModel as any]; | |
/* | |
* Client-Side properties (Not from API) | |
*/ | |
public fullName: string = ''; | |
constructor(data: Partial<PersonModel>) { | |
super(); | |
this.update(data); | |
} | |
public update(data: Partial<PersonModel>): void { | |
super.update(data); | |
this.fullName = `${this.firstName} ${this.lastName}`; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment