I have the following class. I would like to convert the filterOutEmails function to use the array.some
instead of the current code.
export class UsertableComponent {
dataSource: MatTableDataSource<TrialUser>;
createTableFromServer = (data: TrialUsers[], emailDomains:string) => {
this.dataSource = new MatTableDataSource(data);
this.dataSource.filterPredicate = this.filterOutEmails
}
filterOutEmails = (row: TrialUser, emailDomains: string): boolean => {
const listofFilters = emailDomains.split(',');
for (let i = 0; i < listofFilters.length; i++){
if (row.email.toLowerCase().includes(listofFilters[i].trim())){
return true;
};
}
return false;
}
}
I tried doing the following, but it gave this
was null, when I tried to use an arrow function, I couldn't pass in the row. (If I don't set this: TrialUser
as a parameter then, "this" corresponds to Type UsertableComponent, the class the function is in, even though I'm passing in row
to some
as the thisObject)
private determineIfRowShouldBeShown(this: TrialUser, domain: string): boolean {
const row: TrialUser = this;
return !row.email.toLowerCase().includes(domain.trim());
}
private filterOutEmails= (row: TrialUser, emailDomains: string): boolean {
const listofFilters = emailDomains.split(',');
return listofFilters.some(this.determineIfRowShouldBeShown, row) ;
}
}
Putting the 'determineIfRowSHouldBeShown' as an inline fat arrow function works, but I would like to keep the function definition separate.