import { Model } from './Model' ; import { Attributes } from './Attributes' ; import { ApiSync } from './ApiSync' ; import { Eventing } from './Eventing' ; import { Collection } from './Collection' ; export interface UserProps { id ? : number ; name ? : string ; age ? : number ; } const rootUrl = 'http://localhost:3000/users' ; export class User extends Model < UserProps > { static buildUser ( attrs ) { return new User ( new Attributes < UserProps > ( attrs ) , new Eventing ( ) , new ApiSync < UserProps > ( rootUrl ) ) ; } static buildUserCollection ( ) { return new Collection < User , UserProps > ( rootUrl , ( json ) => User . buildUser ( json ) ) ; } setRandomAge ( ) { const age = Math . round ( Math . random ( ) * 100 ) ; this . set ( { age } ) ; } }