From 6a3986e58856e883f4249a0e58150bf2d512bbca Mon Sep 17 00:00:00 2001 From: Xaver Maierhofer Date: Wed, 29 Mar 2017 00:45:52 +0200 Subject: [PATCH] [TASK] Remove instead of add filter twice --- lib/datadistributor.js | 19 +++++++++++++++---- lib/filters/genericnode.js | 7 ++++++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/lib/datadistributor.js b/lib/datadistributor.js index 32e5c1c..ea0bf75 100644 --- a/lib/datadistributor.js +++ b/lib/datadistributor.js @@ -54,10 +54,21 @@ define(['filters/nodefilter'], function (NodeFilter) { } function addFilter(d) { - filters.push(d); - notifyObservers(); - d.setRefresh(refresh); - refresh(); + var newItem = true; + + filters.forEach(function (f) { + if (f.getKey && f.getKey() === d.getKey()) { + removeFilter(f); + newItem = false; + } + }); + + if (newItem) { + filters.push(d); + notifyObservers(); + d.setRefresh(refresh); + refresh(); + } } function removeFilter(d) { diff --git a/lib/filters/genericnode.js b/lib/filters/genericnode.js index cef74c6..ca43a38 100644 --- a/lib/filters/genericnode.js +++ b/lib/filters/genericnode.js @@ -49,10 +49,15 @@ define(['helper'], function (helper) { }; } + function getKey() { + return value.concat(name); + } + return { run: run, setRefresh: setRefresh, - render: render + render: render, + getKey: getKey }; }; });