From 653a329698a27fd2917d28cc33cd2591018f987d Mon Sep 17 00:00:00 2001 From: Nils Schneider Date: Wed, 8 Jul 2015 21:17:00 +0200 Subject: [PATCH] filters: combine filters first --- lib/datadistributor.js | 12 ++++++++---- lib/filters/genericnode.js | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/datadistributor.js b/lib/datadistributor.js index e19dc4c..67cf7eb 100644 --- a/lib/datadistributor.js +++ b/lib/datadistributor.js @@ -1,4 +1,4 @@ -define([], function () { +define(["filters/nodefilter"], function (NodeFilter) { return function () { var targets = [] var filterObservers = [] @@ -26,9 +26,13 @@ define([], function () { if (data === undefined) return - filteredData = filters.reduce( function (a, f) { - return f.run(a) - }, data) + var filter = filters.reduce( function (a, f) { + return function (d) { + return a(d) && f.run(d) + } + }, function () { return true }) + + filteredData = new NodeFilter(filter)(data) targets.forEach( function (t) { t.setData(filteredData) diff --git a/lib/filters/genericnode.js b/lib/filters/genericnode.js index 936e71d..4c2a09d 100644 --- a/lib/filters/genericnode.js +++ b/lib/filters/genericnode.js @@ -1,4 +1,4 @@ -define(["filters/nodefilter"], function (nodefilter) { +define([], function () { return function (name, key, value, f) { var negate = false var refresh @@ -44,7 +44,7 @@ define(["filters/nodefilter"], function (nodefilter) { } } - return { run: nodefilter(run), + return { run: run, setRefresh: setRefresh, render: render }