Skip to content

Commit

Permalink
#407 Move filtering into separate collection method
Browse files Browse the repository at this point in the history
  • Loading branch information
Luis Correia authored and calavera committed May 25, 2017
1 parent 544cb78 commit 7e7642c
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/backends/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,7 @@ class Backend {
// If this collection has a "filter" property, filter entries accordingly
.then(loadedCollection => (
{
entries: loadedCollection.entries.filter(
entry => (!collectionFilter || entry.data[collectionFilter.get('field')] === collectionFilter.get('value'))
),
entries: collectionFilter ? this.filterEntries(loadedCollection, collectionFilter) : loadedCollection.entries
}
));
}
Expand Down Expand Up @@ -249,6 +247,12 @@ class Backend {
}
return file.get('fields').map(f => f.get('name')).toArray();
}

filterEntries(collection, filterRule) {
return collection.entries.filter(entry => (
entry.data[filterRule.get('field')] === filterRule.get('value')
));
}
}

export function resolveBackend(config) {
Expand Down

0 comments on commit 7e7642c

Please sign in to comment.