From 9d5ac6d945bde6ec8255f3ee8a58052c44206fec Mon Sep 17 00:00:00 2001 From: Side Halk <35532148+SideHalk@users.noreply.github.com> Date: Thu, 30 Aug 2018 01:43:20 +0200 Subject: [PATCH] Fixed updateFiltered and removeFiltered Both functions selected members of the collections whenever any of the parameters matched instead of all of them --- lib/util.js | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/lib/util.js b/lib/util.js index a43a182..956b7bf 100644 --- a/lib/util.js +++ b/lib/util.js @@ -27,12 +27,15 @@ export const updateFiltered = (collection, query, data, multi) => { let i = collection.length - 1; loop: for (i; i >= 0; i--) { const c = collection[i]; + var addThis = true; for (var p in query) { - if (p in c && c[p] == query[p]) { - collection[i] = merge(c, data); - if (!multi) { - break loop; - } + if (!(p in c && c[p] == query[p])) + addThis = false; + } + if (addThis) { + collection[i] = merge(c, data); + if (!multi) { + break loop; } } } @@ -45,12 +48,15 @@ export const removeFiltered = (collection, query, multi) => { let i = collection.length - 1; loop: for (i; i >= 0; i--) { var c = collection[i]; + var rmvThis = true; for (var p in query) { - if (p in c && c[p] == query[p]) { - collection.splice(i, 1); - if (!multi) { - break loop; - } + if (!(p in c && c[p] == query[p])) + rmvThis = false; + } + if (rmvThis) { + collection.splice(i, 1); + if (!multi) { + break loop; } } }