import { observable , computed , action , useStrict } from 'mobx' ; import * as CONTACTS from 'contacts-mvc-data' ; import { Contact } from './interfaces' ; useStrict ( true ) ; export class AppState { @ observable public selectedContact : Contact = null ; @ observable public contacts : Array < Contact > = CONTACTS as any ; @ observable public searchQuery : string = '' ; @ computed get filteredContacts ( ) { if ( ! this . searchQuery ) { return this . contacts ; } return this . contacts . filter ( contact => match ( contact , this . searchQuery ) ) ; function match ( contact , query ) { return contains ( contact . firstName , query ) || contains ( contact . lastName , query ) ; } function contains ( str = '' , query = '' ) { return str . toLocaleLowerCase ( ) . indexOf ( query . toLocaleLowerCase ( ) ) > - 1 ; } } @ action selectContact ( contact ) { this . selectedContact = contact ; } @ action search ( query ) { this . searchQuery = query ; } }