Skip to content

Commit 88727c4

Browse files
author
Georgii Rychko
authored
Merge pull request #216 from valor-software/master
sync develop with master
2 parents f3edc09 + 36a4760 commit 88727c4

File tree

3 files changed

+29
-26
lines changed

3 files changed

+29
-26
lines changed

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
<a name="2.0.0-rc.6"></a>
2+
# [2.0.0-rc.6](https://github.com/valor-software/ng2-tree/compare/v2.0.0-rc.5...v2.0.0-rc.6) (2018-02-12)
3+
4+
5+
### Bug Fixes
6+
7+
* **checkboxes:** get rid of performance issue with cyclic event firing; fix indetermined state ([55b975e](https://github.com/valor-software/ng2-tree/commit/55b975e))
8+
9+
10+
111
<a name="2.0.0-rc.5"></a>
212
# [2.0.0-rc.5](https://github.com/valor-software/ng2-tree/compare/v2.0.0-rc.4...v2.0.0-rc.5) (2018-02-11)
313

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ng2-tree",
3-
"version": "2.0.0-rc.5",
3+
"version": "2.0.0-rc.6",
44
"description": "angular2 component for visualizing data that can be naturally represented as a tree",
55
"main": "index.js",
66
"license": "MIT",

src/tree-internal.component.ts

+18-25
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
AfterContentChecked,
2+
AfterViewInit,
33
Component,
44
ElementRef,
55
Input,
@@ -12,18 +12,18 @@ import {
1212
} from '@angular/core';
1313

1414
import * as TreeTypes from './tree.types';
15-
import {Ng2TreeSettings} from './tree.types';
16-
import {Tree} from './tree';
17-
import {TreeController} from './tree-controller';
18-
import {NodeMenuService} from './menu/node-menu.service';
19-
import {NodeMenuItemAction, NodeMenuItemSelectedEvent} from './menu/menu.events';
20-
import {NodeEditableEvent, NodeEditableEventAction} from './editable/editable.events';
21-
import {NodeCheckedEvent, NodeEvent} from './tree.events';
22-
import {TreeService} from './tree.service';
15+
import { Ng2TreeSettings } from './tree.types';
16+
import { Tree } from './tree';
17+
import { TreeController } from './tree-controller';
18+
import { NodeMenuService } from './menu/node-menu.service';
19+
import { NodeMenuItemAction, NodeMenuItemSelectedEvent } from './menu/menu.events';
20+
import { NodeEditableEvent, NodeEditableEventAction } from './editable/editable.events';
21+
import { NodeCheckedEvent, NodeEvent } from './tree.events';
22+
import { TreeService } from './tree.service';
2323
import * as EventUtils from './utils/event.utils';
24-
import {NodeDraggableEvent} from './draggable/draggable.events';
25-
import {Subscription} from 'rxjs/Subscription';
26-
import {get, isNil} from './utils/fn.utils';
24+
import { NodeDraggableEvent } from './draggable/draggable.events';
25+
import { Subscription } from 'rxjs/Subscription';
26+
import { get, isNil } from './utils/fn.utils';
2727

2828
@Component({
2929
selector: 'tree-internal',
@@ -80,7 +80,7 @@ import {get, isNil} from './utils/fn.utils';
8080
</ul>
8181
`
8282
})
83-
export class TreeInternalComponent implements OnInit, OnChanges, OnDestroy, AfterContentChecked {
83+
export class TreeInternalComponent implements OnInit, OnChanges, OnDestroy, AfterViewInit {
8484
@Input()
8585
public tree: Tree;
8686

@@ -106,11 +106,9 @@ export class TreeInternalComponent implements OnInit, OnChanges, OnDestroy, Afte
106106
public nodeElementRef: ElementRef) {
107107
}
108108

109-
public ngAfterContentChecked(): void {
110-
// if a node was checked in settings
111-
// we should notify parent nodes about this
112-
// (they need to switch to appropriate state as well)
113-
if (this.tree.checked) {
109+
public ngAfterViewInit(): void {
110+
if (this.tree.checked && !(this.tree as any).firstCheckedFired) {
111+
(this.tree as any).firstCheckedFired = true;
114112
this.treeService.fireNodeChecked(this.tree);
115113
}
116114
}
@@ -151,9 +149,7 @@ export class TreeInternalComponent implements OnInit, OnChanges, OnDestroy, Afte
151149

152150
this.subscriptions.push(this.treeService.nodeChecked$.merge(this.treeService.nodeUnchecked$)
153151
.filter((e: NodeCheckedEvent) => this.eventContainsId(e) && this.tree.hasChild(e.node))
154-
.subscribe((e: NodeCheckedEvent) => {
155-
this.updateCheckboxState();
156-
}));
152+
.subscribe((e: NodeCheckedEvent) => this.updateCheckboxState()));
157153
}
158154

159155
public ngOnChanges(changes: SimpleChanges): void {
@@ -335,10 +331,6 @@ export class TreeInternalComponent implements OnInit, OnChanges, OnDestroy, Afte
335331
}
336332

337333
updateCheckboxState(): void {
338-
if (!this.checkboxElementRef) {
339-
return;
340-
}
341-
342334
// Calling setTimeout so the value of isChecked will be updated and after that I'll check the children status.
343335
setTimeout(() => {
344336
const checkedChildrenAmount = this.tree.checkedChildrenAmount();
@@ -351,6 +343,7 @@ export class TreeInternalComponent implements OnInit, OnChanges, OnDestroy, Afte
351343
this.tree.checked = true;
352344
this.treeService.fireNodeChecked(this.tree);
353345
} else {
346+
this.tree.checked = false;
354347
this.checkboxElementRef.nativeElement.indeterminate = true;
355348
this.treeService.fireNodeIndetermined(this.tree);
356349
}

0 commit comments

Comments
 (0)