Skip to content

Commit

Permalink
closeNode too aggressive in removing currently opened nodes (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
acierto authored and cheton committed Jan 31, 2018
1 parent 63dac63 commit 7c85187
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 24 deletions.
14 changes: 5 additions & 9 deletions dist/infinite-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -1471,7 +1471,7 @@ var InfiniteTree = function (_events$EventEmitter) {

node.state.open = false; // Set the open state to false
var openNodes = _this4.state.openNodes.filter(function (node) {
return node.hasChildren() && node.state.open;
return node.state.open;
});
_this4.state.openNodes = openNodes;

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

this.state.openNodes = this.nodes.filter(function (node) {
return node.hasChildren() && node.state.open;
return node.state.open;
});
this.state.selectedNode = null;

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

if (nodes.length === 0 && currentNodeIndex >= 0) {
node.state.open = true;

if (_this6.state.openNodes.indexOf(node) < 0) {
// the most recently used items first
_this6.state.openNodes = [node].concat(_this6.state.openNodes);
}
_this6.state.openNodes = [node].concat(_this6.state.openNodes);
}

if (err || nodes.length === 0) {
Expand Down Expand Up @@ -2130,7 +2126,7 @@ var InfiniteTree = function (_events$EventEmitter) {
{
// Update open nodes and lookup table
this.state.openNodes = this.state.openNodes.filter(function (node) {
return removedNodes.indexOf(node) < 0 && node.hasChildren() && node.state.open;
return removedNodes.indexOf(node) < 0 && node.state.open;
});

removedNodes.forEach(function (node) {
Expand Down Expand Up @@ -2221,7 +2217,7 @@ var InfiniteTree = function (_events$EventEmitter) {
{
// Update open nodes and lookup table
this.state.openNodes = this.state.openNodes.filter(function (node) {
return removedNodes.indexOf(node) < 0 && node.hasChildren() && node.state.open;
return removedNodes.indexOf(node) < 0 && node.state.open;
});

removedNodes.forEach(function (node) {
Expand Down
2 changes: 1 addition & 1 deletion dist/infinite-tree.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/examples.js

Large diffs are not rendered by default.

18 changes: 5 additions & 13 deletions src/infinite-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -599,9 +599,7 @@ class InfiniteTree extends events.EventEmitter {
}

node.state.open = false; // Set the open state to false
const openNodes = this.state.openNodes.filter((node) => {
return node.hasChildren() && node.state.open;
});
const openNodes = this.state.openNodes.filter((node) => node.state.open);
this.state.openNodes = openNodes;

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

this.state.openNodes = this.nodes.filter((node) => {
return node.hasChildren() && node.state.open;
});
this.state.openNodes = this.nodes.filter((node) => node.state.open);
this.state.selectedNode = null;

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

if (nodes.length === 0 && currentNodeIndex >= 0) {
node.state.open = true;

if (this.state.openNodes.indexOf(node) < 0) {
// the most recently used items first
this.state.openNodes = [node].concat(this.state.openNodes);
}
this.state.openNodes = [node].concat(this.state.openNodes);
}

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

{ // Update open nodes and lookup table
this.state.openNodes = this.state.openNodes.filter((node) => {
return (removedNodes.indexOf(node) < 0) && node.hasChildren() && node.state.open;
return (removedNodes.indexOf(node) < 0) && node.state.open;
});

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

{ // Update open nodes and lookup table
this.state.openNodes = this.state.openNodes.filter((node) => {
return (removedNodes.indexOf(node) < 0) && node.hasChildren() && node.state.open;
return (removedNodes.indexOf(node) < 0) && node.state.open;
});

removedNodes.forEach((node) => {
Expand Down

0 comments on commit 7c85187

Please sign in to comment.