Allow searching & filtering to mutate the data they receive (not their job :)

This commit is contained in:
John Furrow
2015-12-15 23:32:11 -08:00
parent 2529a97065
commit 3a56da6d1c
2 changed files with 7 additions and 12 deletions
+5 -8
View File
@@ -1,13 +1,10 @@
export function filterTorrents(torrentList, torrentListFilterBy) {
let filteredtorrentList = torrentList;
if (torrentListFilterBy !== 'all') {
filteredtorrentList = torrentList.filter(torrent => {
if (torrent.status.indexOf('is-' + torrentListFilterBy) > -1) {
export function filterTorrents(torrents, filterBy) {
if (filterBy !== 'all') {
torrents = torrentList.filter(torrent => {
if (torrent.status.indexOf('is-' + filterBy) > -1) {
return torrent;
}
});
}
return filteredtorrentList;
return torrents;
}
+2 -4
View File
@@ -1,6 +1,4 @@
export function searchTorrents(torrents, searchString) {
let searchedTorrents = torrents;
if (searchString !== '') {
let queries = [];
let searchTerms = searchString.replace(/,/g, ' ').split(' ');
@@ -9,7 +7,7 @@ export function searchTorrents(torrents, searchString) {
queries.push(new RegExp(searchTerms[i], 'gi'));
}
searchedTorrents = searchedTorrents.filter(torrent => {
torrents = torrents.filter((torrent) => {
for (let i = 0, len = queries.length; i < len; i++) {
if (!torrent.name.match(queries[i])) {
return false;
@@ -19,5 +17,5 @@ export function searchTorrents(torrents, searchString) {
});
}
return searchedTorrents;
return torrents;
}