summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--slick.dataview.js16
-rw-r--r--tests/dataview/dataview.js34
2 files changed, 42 insertions, 8 deletions
diff --git a/slick.dataview.js b/slick.dataview.js
index 45439b6..5bee4ff 100644
--- a/slick.dataview.js
+++ b/slick.dataview.js
@@ -613,10 +613,10 @@
var filterInfo = getFunctionInfo(filter);
var filterBody = filterInfo.body
- .replace(/return false[;}]/gi, "{ continue _coreloop; }")
- .replace(/return true[;}]/gi, "{ _retval[_idx++] = $item$; continue _coreloop; }")
- .replace(/return ([^;}]+?);/gi,
- "{ if ($1) { _retval[_idx++] = $item$; }; continue _coreloop; }");
+ .replace(/return false\s*([;}]|$)/gi, "{ continue _coreloop; }$1")
+ .replace(/return true\s*([;}]|$)/gi, "{ _retval[_idx++] = $item$; continue _coreloop; }$1")
+ .replace(/return ([^;}]+?)\s*([;}]|$)/gi,
+ "{ if ($1) { _retval[_idx++] = $item$; }; continue _coreloop; }$2");
// This preserves the function template code after JS compression,
// so that replace() commands still work as expected.
@@ -645,10 +645,10 @@
var filterInfo = getFunctionInfo(filter);
var filterBody = filterInfo.body
- .replace(/return false[;}]/gi, "{ continue _coreloop; }")
- .replace(/return true[;}]/gi, "{ _cache[_i] = true;_retval[_idx++] = $item$; continue _coreloop; }")
- .replace(/return ([^;}]+?);/gi,
- "{ if ((_cache[_i] = $1)) { _retval[_idx++] = $item$; }; continue _coreloop; }");
+ .replace(/return false\s*([;}]|$)/gi, "{ continue _coreloop; }$1")
+ .replace(/return true\s*([;}]|$)/gi, "{ _cache[_i] = true;_retval[_idx++] = $item$; continue _coreloop; }$1")
+ .replace(/return ([^;}]+?)\s*([;}]|$)/gi,
+ "{ if ((_cache[_i] = $1)) { _retval[_idx++] = $item$; }; continue _coreloop; }$2");
// This preserves the function template code after JS compression,
// so that replace() commands still work as expected.
diff --git a/tests/dataview/dataview.js b/tests/dataview/dataview.js
index 04278c1..c1eb384 100644
--- a/tests/dataview/dataview.js
+++ b/tests/dataview/dataview.js
@@ -377,6 +377,40 @@ test("all then none", function() {
assertConsistency(dv);
});
+test("inlining replaces absolute returns", function() {
+ var dv = new Slick.Data.DataView({ inlineFilters: true });
+ dv.setItems([{id:0,val:0},{id:1,val:1},{id:2,val:2}]);
+ dv.setFilter(function(o) {
+ if (o.val === 1) { return true; }
+ else if (o.val === 4) { return true }
+ return false});
+ same(dv.getLength(), 1, "one row is remaining");
+
+ dv.onRowsChanged.subscribe(function() { ok(false, "onRowsChanged called") });
+ dv.onRowCountChanged.subscribe(function() { ok(false, "onRowCountChanged called") });
+ dv.onPagingInfoChanged.subscribe(function() { ok(false, "onPagingInfoChanged called") });
+ same(dv.getItems().length, 3, "original data is still there");
+ same(dv.getLength(), 1, "rows are filtered");
+ assertConsistency(dv);
+});
+
+test("inlining replaces evaluated returns", function() {
+ var dv = new Slick.Data.DataView({ inlineFilters: true });
+ dv.setItems([{id:0,val:0},{id:1,val:1},{id:2,val:2}]);
+ dv.setFilter(function(o) {
+ if (o.val === 0) { return o.id === 2; }
+ else if (o.val === 1) { return o.id === 2 }
+ return o.val === 2});
+ same(dv.getLength(), 1, "one row is remaining");
+
+ dv.onRowsChanged.subscribe(function() { ok(false, "onRowsChanged called") });
+ dv.onRowCountChanged.subscribe(function() { ok(false, "onRowCountChanged called") });
+ dv.onPagingInfoChanged.subscribe(function() { ok(false, "onPagingInfoChanged called") });
+ same(dv.getItems().length, 3, "original data is still there");
+ same(dv.getLength(), 1, "rows are filtered");
+ assertConsistency(dv);
+});
+
module("updateItem");
test("basic", function() {