import { EventList } from './eventList.model' ; export class Settings { username : String ; eventLists : Array < EventList > ; constructor ( username , savedLists ) { this . username = username ; this . eventLists = this . deserializeEventLists ( savedLists ) ; } public toJson ( ) { return { username : this . username , eventList : this . eventLists } ; } private deserializeEventLists ( data ) { const lists = new Array < EventList > ( ) ; let eventLists ; if ( typeof data === 'string' ) { eventLists = JSON . parse ( data ) ; } else { eventLists = data ; } if ( eventLists !== null ) { eventLists . forEach ( list => { const currentEventList = new EventList ( list . id , list . title , JSON . parse ( JSON . stringify ( list . filter ) ) , list . activeEvents ) ; lists . push ( currentEventList ) ; } ) ; } else { console . log ( 'Did not find any event lists, setting a new one.' ) ; } return lists ; } }