license import { Injectable , OnDestroy } from '@angular/core' ; export type UniqueSelectionDispatcherListener = ( id : string , name : string ) => void ; /**
 * Class to coordinate unique selection based on name.
 * Intended to be consumed as an Angular service.
 * This service is needed because native radio change events are only fired on the item currently
 * being selected, and we still need to uncheck the previous selection.
 *
 * This service does not *store* any IDs and names because they may change at any time, so it is
 * less error-prone if they are simply passed through when the events occur.
 */ @ Injectable ( { providedIn : 'root' } ) export class UniqueSelectionDispatcher implements OnDestroy { private _listeners : UniqueSelectionDispatcherListener [ ] = [ ] ; param id param name notify ( id , name ) { for ( let listener of this . _listeners ) { listener ( id , name ) ; } } return listen ( listener ) { this . _listeners . push ( listener ) ; return ( ) => { this . _listeners = this . _listeners . filter ( ( registered ) => { return listener !== registered ; } ) ; } ; } ngOnDestroy ( ) { this . _listeners = [ ] ; } }