Skip to content

Commit

Permalink
only destroy children when they are nodes
Browse files Browse the repository at this point in the history
this._children aren't all CollapseTreeNodes. some of the are regular values
  • Loading branch information
addepar-andy authored May 18, 2018
2 parents cdbd543 + 33aa3b3 commit 43ceb0e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
10 changes: 8 additions & 2 deletions addon/-private/collapse-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ class CollapseTreeNode extends EmberObject {
*/
cleanChildren() {
if (this._children) {
this._children.forEach(n => n.destroy());
for (let child of this._children) {
if (child instanceof CollapseTreeNode) {
child.destroy();
}
}
this._children = null;
}
}
Expand Down Expand Up @@ -367,7 +371,9 @@ export default class CollapseTree extends EmberObject.extend(EmberArray) {
destroy() {
super.destroy(...arguments);

this._root.destroy();
if (this._root) {
this._root.destroy();
}
}

/*
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"dependencies": {
"@addepar/ember-toolbox": "^0.3.2",
"@ember-decorators/argument": "^0.8.10",
"@ember-decorators/argument": "^0.8.15",
"@ember-decorators/babel-transforms": "^0.1.1",
"@html-next/vertical-collection": "1.0.0-beta.10",
"css-element-queries": "^0.4.0",
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/-private/collapse-tree-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { module, test } from 'qunit';
import { A as emberA } from '@ember/array';
import { get, set } from '@ember/object';
import { run } from '@ember/runloop';

import CollapseTree from 'ember-table/-private/collapse-tree';

Expand Down Expand Up @@ -179,4 +180,14 @@ module('Unit | Private | CollapseTree', function() {
assert.equal(collapseTree.objectAt(i).parents.length, expectedDepth[i]);
}
});

test('works with single level tree', function(assert) {
let rows = [{ label: 'A', children: [] }, { label: 'B', children: [] }];
let tree = CollapseTree.create({ tree: rows });
run(() => {
tree.get('length');
tree.destroy();
assert.ok(true, 'exception not thrown');
});
});
});

0 comments on commit 43ceb0e

Please sign in to comment.