import Record from "./record" ; import Client from "./client" ; export default class RecordList < T extends Record > { public idValue : string = "mock-record-list" ; public recordsValue : T [ ] = [ ] ; public isDeletedValue : boolean = false ; public static TYPE_SENTINAL = { } ; public static Type < T > ( RecordConstructor ) { return { TYPE_SENTINAL : RecordList . TYPE_SENTINAL , RecordConstructor , } ; } private recordConstructor_ : { new ( ) : T ; } ; constructor ( client , RecordConstructor ) { this . recordConstructor_ = RecordConstructor ; } getId ( ) { return this . idValue ; } getRecords ( ) { return this . recordsValue ; } count ( ) { return this . recordsValue . length ; } add ( value , index ? , isProgrammatic ? ) { const RecordConstructor = this . recordConstructor_ ; const item = new RecordConstructor ( ) ; item . initialize ( ) ; item . containingListValue = this ; for ( const key in value ) { item . set ( key , value [ key ] ) ; } if ( index === undefined ) { this . recordsValue . push ( item ) ; } else { this . recordsValue . splice ( index , 0 , item ) ; } return item ; } contains ( item ) { return ! ! this . recordsValue . find ( i => i === item ) ; } delete ( isProgrammaticUpdate ? ) { this . isDeletedValue = true ; } get ( index ) { return this . recordsValue [ index ] ; } indexOf ( item ) { return this . recordsValue . findIndex ( i => i === item ) ; } isDeleted ( ) { this . isDeletedValue ; } move ( item , index , isProgrammaticUpdate ? ) { const parent = item . containingListValue ; if ( index < 0 ) { return false ; } if ( parent ) { parent . remove ( item ) ; this . recordsValue . splice ( index , 0 , item ) ; } return true ; } remove ( item , skipDelete ? , isProgrammaticUpdate ? ) { const idx = this . indexOf ( item ) ; if ( idx > - 1 ) { this . recordsValue . splice ( idx , 1 ) ; return true ; } return false ; } listen ( listener ) { } unlisten ( listener ) { } } export type listPropertyType < T > = { TYPE_SENTINAL : Object ; RecordConstructor : { new ( ) : T ; } ; } ;