export class AssociativeStore < T > { private store : T = null ; constructor ( ) { this . initStore ( ) ; } public initStore = ( ) => { this . store = < T > { } ; } ; public deleteStore = ( ) => { this . initStore ( ) ; } ; public count = ( ) : number => { if ( this . store != null ) { return Object . keys ( this . store ) . length ; } else { return 0 ; } } ; public getItem = ( id ) : any => { return this . store [ id ] ; } ; public setItem = ( item , id ) => { this . store [ id ] = item ; } ; public deleteItem = ( id ) => { delete this . store [ id ] ; } ; public getAllItems = ( ) : Array < T > => { let arr = [ ] ; for ( const key in this . store ) { arr . push ( this . store [ key ] ) ; } return arr ; } ; public createStoreFromArray = ( arr ) => { this . initStore ( ) ; for ( const i in arr ) { this . store [ arr [ i ] [ '_id' ] ] = arr [ i ] ; } } ; }