Item predicate matching

This commit is contained in:
Mo Bitar
2018-07-03 18:21:55 -05:00
parent 8c9fd9308d
commit 662b3d6a07
2 changed files with 16 additions and 27 deletions

View File

@@ -125,32 +125,10 @@ class SingletonManager {
filterItemsWithPredicate(items, predicate) {
return items.filter((candidate) => {
return this.itemSatisfiesPredicate(candidate, predicate);
return candidate.satisfiesPredicate(predicate);
})
}
itemSatisfiesPredicate(candidate, predicate) {
for(var key in predicate) {
var predicateValue = predicate[key];
var candidateValue = candidate[key];
if(typeof predicateValue == 'object') {
// Check nested properties
if(!candidateValue) {
// predicateValue is 'object' but candidateValue is null
return false;
}
if(!this.itemSatisfiesPredicate(candidateValue, predicateValue)) {
return false;
}
}
else if(candidateValue != predicateValue) {
return false;
}
}
return true;
}
}
angular.module('app').service('singletonManager', SingletonManager);