Skip to content

Commit

Permalink
Node with loadOnDemand which has 0 children doesn't update the state …
Browse files Browse the repository at this point in the history
…with openNodes (#25)

* Fixed the regression in addChildNodes

* wip

* rebuilt dist & examples

* applied feedback

* fix for addChildNodes on empty parent node

* merged upstream/master

* fix

* updated docs

* added more assertions
  • Loading branch information
acierto authored and cheton committed Jan 31, 2018
1 parent 7bca7c6 commit 2bf9482
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions dist/infinite-tree.js
Expand Up @@ -1983,6 +1983,7 @@ var InfiniteTree = function (_events$EventEmitter) {

if (nodes.length === 0 && currentNodeIndex >= 0) {
node.state.open = true;
_this6.state.openNodes = [node].concat(_this6.state.openNodes);
}

if (err || nodes.length === 0) {
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.

1 change: 1 addition & 0 deletions src/infinite-tree.js
Expand Up @@ -1069,6 +1069,7 @@ class InfiniteTree extends events.EventEmitter {

if (nodes.length === 0 && currentNodeIndex >= 0) {
node.state.open = true;
this.state.openNodes = [node].concat(this.state.openNodes);
}

if (err || nodes.length === 0) {
Expand Down
3 changes: 3 additions & 0 deletions test/index.js
Expand Up @@ -143,7 +143,9 @@ test('loadOnDemand', (t) => {
setTimeout(() => {
next(null, [], () => {
t.equal(tree.getNodeById('<root>').getChildren().length, 0);
t.equal(tree.state.openNodes.length, 1);
t.equal(node.state.open, true);
t.end();
});
}, 250);

Expand All @@ -152,6 +154,7 @@ test('loadOnDemand', (t) => {
const data = getTreeData();
next(null, data.children, () => {
t.equal(tree.getNodeById('<root>').getChildren().length, 2);
t.equal(tree.state.openNodes.length, 1);
t.end();
});
}, 500);
Expand Down

0 comments on commit 2bf9482

Please sign in to comment.