Skip to content

Commit d3b2e4a

Browse files
committed
Fix reindex and group listeners on data removal.
There was a bug where the new index was not always being copied. In addition, the updateMany/updateOne/null behaviour, was not being updated for groups on data removal.
1 parent ac1de20 commit d3b2e4a

File tree

5 files changed

+55
-15
lines changed

5 files changed

+55
-15
lines changed

crossfilter.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(function(exports){
2-
crossfilter.version = "1.3.4";
2+
crossfilter.version = "1.3.5";
33
function crossfilter_identity(d) {
44
return d;
55
}
@@ -699,7 +699,8 @@ function crossfilter() {
699699
function removeData(reIndex) {
700700
for (var i = 0, j = 0, k; i < n; ++i) {
701701
if (filters[k = index[i]]) {
702-
if (i !== j) values[j] = values[i], index[j] = reIndex[k];
702+
if (i !== j) values[j] = values[i];
703+
index[j] = reIndex[k];
703704
++j;
704705
}
705706
}
@@ -1008,7 +1009,7 @@ function crossfilter() {
10081009
}
10091010

10101011
function removeData() {
1011-
if (groupIndex) {
1012+
if (k > 1) {
10121013
var oldK = k,
10131014
oldGroups = groups,
10141015
seenGroups = crossfilter_index(oldK, oldK);
@@ -1033,8 +1034,21 @@ function crossfilter() {
10331034
}
10341035
}
10351036

1036-
// Reindex the group index using seenGroups to find the new index.
1037-
for (var i = 0; i < j; ++i) groupIndex[i] = seenGroups[groupIndex[i]];
1037+
if (k > 1) {
1038+
// Reindex the group index using seenGroups to find the new index.
1039+
for (var i = 0; i < j; ++i) groupIndex[i] = seenGroups[groupIndex[i]];
1040+
} else {
1041+
groupIndex = null;
1042+
}
1043+
filterListeners[filterListeners.indexOf(update)] = k > 1
1044+
? (reset = resetMany, update = updateMany)
1045+
: k === 1 ? (reset = resetOne, update = updateOne)
1046+
: reset = update = crossfilter_null;
1047+
} else if (k === 1) {
1048+
for (var i = 0; i < n; ++i) if (filters[i]) return;
1049+
groups = [], k = 0;
1050+
filterListeners[filterListeners.indexOf(update)] =
1051+
update = reset = crossfilter_null;
10381052
}
10391053
}
10401054

crossfilter.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)