import { ChangeDetectorRef , OnDestroy , Pipe , PipeTransform } from '@angular/core' ; import { OnChangedEvent , OWHotkeys } from '@app/odk' ; @ Pipe ( { name : 'hotkey' , pure : false } ) export class HotkeyPipe implements PipeTransform , OnDestroy { private binding : string ; private name : string ; constructor ( private ref ) { } public ngOnDestroy ( ) { OWHotkeys . onChanged . removeListener ( this . onChange ) ; } public transform ( name ) { if ( name === this . name ) { return this . binding ; } this . name = name ; OWHotkeys . getHotkeyText ( this . name ) . subscribe ( text => { this . updateText ( text ) ; } ) ; OWHotkeys . onChanged . removeListener ( this . onChange ) ; OWHotkeys . onChanged . addListener ( this . onChange ) ; return this . binding ; } private onChange = ( event ) => { if ( event . name === this . name && this . binding !== event . binding ) { this . updateText ( event . binding ) ; } } ; private updateText ( text ) { this . binding = text ; this . ref . markForCheck ( ) ; } }