1- import { Input , Component , OnInit , OnDestroy , ElementRef , Inject } from '@angular/core' ;
1+ import { Component , ElementRef , Inject , Input , OnDestroy , OnInit } from '@angular/core' ;
22import * as TreeTypes from './tree.types' ;
33import { Tree } from './tree' ;
44import { TreeController } from './tree-controller' ;
55import { NodeMenuService } from './menu/node-menu.service' ;
6- import { NodeMenuItemSelectedEvent , NodeMenuItemAction } from './menu/menu.events' ;
6+ import { NodeMenuItemAction , NodeMenuItemSelectedEvent } from './menu/menu.events' ;
77import { NodeEditableEvent , NodeEditableEventAction } from './editable/editable.events' ;
88import { TreeService } from './tree.service' ;
99import * as EventUtils from './utils/event.utils' ;
1010import { NodeDraggableEvent } from './draggable/draggable.events' ;
11- import { Observable } from 'rxjs/Rx' ;
1211import * as _get from 'lodash/get' ;
12+ import { Subscription } from 'rxjs/Subscription' ;
1313
1414@Component ( {
1515 selector : 'tree-internal' ,
@@ -66,6 +66,8 @@ export class TreeInternalComponent implements OnInit, OnDestroy {
6666 public isLeftMenuVisible = false ;
6767 public controller : TreeController ;
6868
69+ private subscriptions : Subscription [ ] = [ ] ;
70+
6971 public constructor ( @Inject ( NodeMenuService ) private nodeMenuService : NodeMenuService ,
7072 @Inject ( TreeService ) public treeService : TreeService ,
7173 @Inject ( ElementRef ) public element : ElementRef ) {
@@ -79,16 +81,16 @@ export class TreeInternalComponent implements OnInit, OnDestroy {
7981
8082 this . settings = this . settings || { rootIsVisible : true } ;
8183
82- this . nodeMenuService . hideMenuStream ( this . element )
84+ this . subscriptions . push ( this . nodeMenuService . hideMenuStream ( this . element )
8385 . subscribe ( ( ) => {
8486 this . isRightMenuVisible = false ;
8587 this . isLeftMenuVisible = false ;
86- } ) ;
88+ } ) ) ;
8789
88- this . treeService . unselectStream ( this . tree )
89- . subscribe ( ( ) => this . isSelected = false ) ;
90+ this . subscriptions . push ( this . treeService . unselectStream ( this . tree )
91+ . subscribe ( ( ) => this . isSelected = false ) ) ;
9092
91- this . treeService . draggedStream ( this . tree , this . element )
93+ this . subscriptions . push ( this . treeService . draggedStream ( this . tree , this . element )
9294 . subscribe ( ( e : NodeDraggableEvent ) => {
9395 if ( this . tree . hasSibling ( e . captured . tree ) ) {
9496 this . swapWithSibling ( e . captured . tree , this . tree ) ;
@@ -97,13 +99,15 @@ export class TreeInternalComponent implements OnInit, OnDestroy {
9799 } else {
98100 this . moveNodeToParentTreeAndRemoveFromPreviousOne ( e , this . tree ) ;
99101 }
100- } ) ;
102+ } ) ) ;
101103 }
102104
103105 public ngOnDestroy ( ) : void {
104106 if ( _get ( this . tree , 'node.id' , '' ) ) {
105107 this . treeService . deleteController ( this . tree . node . id ) ;
106108 }
109+
110+ this . subscriptions . forEach ( sub => sub && sub . unsubscribe ( ) ) ;
107111 }
108112
109113 private swapWithSibling ( sibling : Tree , tree : Tree ) : void {
0 commit comments