import { ElementRef , Injectable } from '@angular/core' ; import { Subject } from 'rxjs/Subject' ; import { Observable } from 'rxjs/Observable' ; import { NodeMenuAction , NodeMenuEvent } from './menu.events' ; @ Injectable ( ) export class NodeMenuService { public nodeMenuEvents$ : Subject < NodeMenuEvent > = new Subject < NodeMenuEvent > ( ) ; public fireMenuEvent ( sender , action ) { const nodeMenuEvent = { sender , action } ; this . nodeMenuEvents$ . next ( nodeMenuEvent ) ; } public hideMenuStream ( treeElementRef ) { return this . nodeMenuEvents$ . filter ( ( e ) => treeElementRef . nativeElement !== e . sender ) . filter ( ( e ) => e . action === NodeMenuAction . Close ) ; } public hideMenuForAllNodesExcept ( treeElementRef ) { this . nodeMenuEvents$ . next ( { sender : treeElementRef . nativeElement , action : NodeMenuAction . Close } ) ; } }