import axios , { AxiosResponse } from 'axios' ; import { Eventing } from './Eventing' ; export class Collection < T , K > { models : T [ ] = [ ] ; events : Eventing = new Eventing ( ) ; constructor ( public rootUrl , public deserialize ) { } get on ( ) { return this . events . on ; } get trigger ( ) { return this . events . trigger ; } fetch ( ) { axios . get ( this . rootUrl ) . then ( ( response ) => { response . data . forEach ( ( value ) => { this . models . push ( this . deserialize ( value ) ) ; } ) ; this . trigger ( 'change' ) ; } ) ; } }