I have a filter function that takes in user filter selections and returns data accordingly. Currently, I am using this function in multiple components to avoid repetition (DRY). To streamline the process, I decided to refactor it into a service layer. However, after moving part of the function into the service layer, the data is not being filtered as expected.
Initially, here is the existing component function that is functioning correctly:
public onFilterReceived(value, type, page) {
if (value && type === 'lan') {
this.language = value;
}
else if (value && type === 'location') {
this.location = value;
}
// Remaining conditional logic...
}
// Rest of the code remains the same
After getting the above working, I attempted to separate the initial part of the function responsible for handling conditional logic into a service layer. This resulted in the following service layer implementation:
public processByTypes(value, type) {
let language, location, zipcode, firstName, lastName, branch;
if (value && type === 'lan') {
console.log(value);
language = value;
}
else if (value && type === 'location') {
location = value;
}
// Remaining conditional logic...
}
Subsequently, I updated the component as follows:
public onFilterReceived(value, type, page) {
this.filtersService.processByTypes(value, type);
// Remaining logic...
}
However, this modification is not yielding the expected results.
I verified that the filter selections are reaching the service layer since the "language" console.log successfully displays the user's selection value. Nonetheless, this value is not returned to the component layer for filtering the data appropriately. What crucial detail might be missing from this approach? It could be something glaringly obvious, but perhaps due to prolonged examination, it eludes me.