Skip to content

Commit 7c85187

Browse files
aciertocheton
authored andcommitted
closeNode too aggressive in removing currently opened nodes (#26)
1 parent 63dac63 commit 7c85187

File tree

4 files changed

+12
-24
lines changed

4 files changed

+12
-24
lines changed

dist/infinite-tree.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,7 +1471,7 @@ var InfiniteTree = function (_events$EventEmitter) {
14711471

14721472
node.state.open = false; // Set the open state to false
14731473
var openNodes = _this4.state.openNodes.filter(function (node) {
1474-
return node.hasChildren() && node.state.open;
1474+
return node.state.open;
14751475
});
14761476
_this4.state.openNodes = openNodes;
14771477

@@ -1799,7 +1799,7 @@ var InfiniteTree = function (_events$EventEmitter) {
17991799
this.nodeTable.clear();
18001800

18011801
this.state.openNodes = this.nodes.filter(function (node) {
1802-
return node.hasChildren() && node.state.open;
1802+
return node.state.open;
18031803
});
18041804
this.state.selectedNode = null;
18051805

@@ -1983,11 +1983,7 @@ var InfiniteTree = function (_events$EventEmitter) {
19831983

19841984
if (nodes.length === 0 && currentNodeIndex >= 0) {
19851985
node.state.open = true;
1986-
1987-
if (_this6.state.openNodes.indexOf(node) < 0) {
1988-
// the most recently used items first
1989-
_this6.state.openNodes = [node].concat(_this6.state.openNodes);
1990-
}
1986+
_this6.state.openNodes = [node].concat(_this6.state.openNodes);
19911987
}
19921988

19931989
if (err || nodes.length === 0) {
@@ -2130,7 +2126,7 @@ var InfiniteTree = function (_events$EventEmitter) {
21302126
{
21312127
// Update open nodes and lookup table
21322128
this.state.openNodes = this.state.openNodes.filter(function (node) {
2133-
return removedNodes.indexOf(node) < 0 && node.hasChildren() && node.state.open;
2129+
return removedNodes.indexOf(node) < 0 && node.state.open;
21342130
});
21352131

21362132
removedNodes.forEach(function (node) {
@@ -2221,7 +2217,7 @@ var InfiniteTree = function (_events$EventEmitter) {
22212217
{
22222218
// Update open nodes and lookup table
22232219
this.state.openNodes = this.state.openNodes.filter(function (node) {
2224-
return removedNodes.indexOf(node) < 0 && node.hasChildren() && node.state.open;
2220+
return removedNodes.indexOf(node) < 0 && node.state.open;
22252221
});
22262222

22272223
removedNodes.forEach(function (node) {

dist/infinite-tree.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.

docs/examples.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.

src/infinite-tree.js

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -599,9 +599,7 @@ class InfiniteTree extends events.EventEmitter {
599599
}
600600

601601
node.state.open = false; // Set the open state to false
602-
const openNodes = this.state.openNodes.filter((node) => {
603-
return node.hasChildren() && node.state.open;
604-
});
602+
const openNodes = this.state.openNodes.filter((node) => node.state.open);
605603
this.state.openNodes = openNodes;
606604

607605
// Subtract total from ancestor nodes
@@ -896,9 +894,7 @@ class InfiniteTree extends events.EventEmitter {
896894
// Clear lookup table
897895
this.nodeTable.clear();
898896

899-
this.state.openNodes = this.nodes.filter((node) => {
900-
return node.hasChildren() && node.state.open;
901-
});
897+
this.state.openNodes = this.nodes.filter((node) => node.state.open);
902898
this.state.selectedNode = null;
903899

904900
const rootNode = ((node = null) => {
@@ -1069,11 +1065,7 @@ class InfiniteTree extends events.EventEmitter {
10691065

10701066
if (nodes.length === 0 && currentNodeIndex >= 0) {
10711067
node.state.open = true;
1072-
1073-
if (this.state.openNodes.indexOf(node) < 0) {
1074-
// the most recently used items first
1075-
this.state.openNodes = [node].concat(this.state.openNodes);
1076-
}
1068+
this.state.openNodes = [node].concat(this.state.openNodes);
10771069
}
10781070

10791071
if (err || nodes.length === 0) {
@@ -1212,7 +1204,7 @@ class InfiniteTree extends events.EventEmitter {
12121204

12131205
{ // Update open nodes and lookup table
12141206
this.state.openNodes = this.state.openNodes.filter((node) => {
1215-
return (removedNodes.indexOf(node) < 0) && node.hasChildren() && node.state.open;
1207+
return (removedNodes.indexOf(node) < 0) && node.state.open;
12161208
});
12171209

12181210
removedNodes.forEach((node) => {
@@ -1298,7 +1290,7 @@ class InfiniteTree extends events.EventEmitter {
12981290

12991291
{ // Update open nodes and lookup table
13001292
this.state.openNodes = this.state.openNodes.filter((node) => {
1301-
return (removedNodes.indexOf(node) < 0) && node.hasChildren() && node.state.open;
1293+
return (removedNodes.indexOf(node) < 0) && node.state.open;
13021294
});
13031295

13041296
removedNodes.forEach((node) => {

0 commit comments

Comments
 (0)