Skip to content

Commit

Permalink
Clean up computed property by inverting early return
Browse files Browse the repository at this point in the history
  • Loading branch information
DingoEatingFuzz committed May 5, 2018
1 parent e5ba6eb commit 4f260e2
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions ui/app/mixins/searchable.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,28 +64,34 @@ export default Mixin.create({
'regexSearchProps.[]',
function() {
const searchTerm = this.get('searchTerm').trim();
if (searchTerm && searchTerm.length) {
const results = [];
if (this.get('exactMatchEnabled')) {
results.push(
...exactMatchSearch(
searchTerm,
this.get('listToSearch'),
this.get('exactMatchSearchProps')
)
);
}
if (this.get('fuzzySearchEnabled')) {
results.push(...this.get('fuse').search(searchTerm));
}
if (this.get('regexEnabled')) {
results.push(
...regexSearch(searchTerm, this.get('listToSearch'), this.get('regexSearchProps'))
);
}
return results.uniq();

if (!searchTerm || !searchTerm.length) {
return this.get('listToSearch');
}
return this.get('listToSearch');

const results = [];

if (this.get('exactMatchEnabled')) {
results.push(
...exactMatchSearch(
searchTerm,
this.get('listToSearch'),
this.get('exactMatchSearchProps')
)
);
}

if (this.get('fuzzySearchEnabled')) {
results.push(...this.get('fuse').search(searchTerm));
}

if (this.get('regexEnabled')) {
results.push(
...regexSearch(searchTerm, this.get('listToSearch'), this.get('regexSearchProps'))
);
}

return results.uniq();
}
),
});
Expand Down

0 comments on commit 4f260e2

Please sign in to comment.