Item predicate matching
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user