From 4f260e29df2436d2a6e270519dc26d48ca714f21 Mon Sep 17 00:00:00 2001 From: Michael Lange Date: Fri, 4 May 2018 20:38:55 -0700 Subject: [PATCH] Clean up computed property by inverting early return --- ui/app/mixins/searchable.js | 48 +++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/ui/app/mixins/searchable.js b/ui/app/mixins/searchable.js index f3df9e134..815956c69 100644 --- a/ui/app/mixins/searchable.js +++ b/ui/app/mixins/searchable.js @@ -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(); } ), });