Skip to content

Commit aa44992

Browse files
committed
fix(tree): should not load children when they were already loaded (closes #149)
1 parent a83c1e4 commit aa44992

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/tree.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ export class Tree {
143143
* @returns {boolean} A flag indicating that children should be loaded for the current node.
144144
*/
145145
public childrenShouldBeLoaded(): boolean {
146-
return !!this._loadChildren || this.node.emitLoadNextLevel === true;
146+
return !this.childrenWereLoaded() && (!!this._loadChildren || this.node.emitLoadNextLevel === true);
147147
}
148148

149149
/**

test/tree.spec.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Tree } from '../src/tree';
2-
import { TreeModel, TreeModelSettings, FoldingType, CssClasses } from '../src/tree.types';
2+
import { TreeModel, TreeModelSettings, FoldingType, CssClasses, ChildrenLoadingFunction } from '../src/tree.types';
33

44
describe('Tree', () => {
55
it('should detect empty string', () => {
@@ -1086,6 +1086,17 @@ describe('Tree', () => {
10861086
expect(masterTree.children[1].leftMenuTemplate).toEqual('<i class="navigation"></i>');
10871087
});
10881088

1089+
it('should not load children when they are already loaded', () => {
1090+
const model: TreeModel = {
1091+
value: 'root',
1092+
};
1093+
1094+
const tree: Tree = new Tree(model);
1095+
spyOn(tree, 'childrenWereLoaded').and.returnValue(true);
1096+
1097+
expect(tree.childrenShouldBeLoaded()).toBe(false);
1098+
});
1099+
10891100
it('should load children when hasChildren is true', () => {
10901101

10911102
const model: TreeModel = {

0 commit comments

Comments
 (0)