/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ import { Injectable } from '@angular/core'; import * as i0 from "@angular/core"; /** * 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. */ export class UniqueSelectionDispatcher { constructor() { this._listeners = []; } /** * Notify other items that selection for the given name has been set. * @param id ID of the item. * @param name Name of the item. */ notify(id, name) { for (let listener of this._listeners) { listener(id, name); } } /** * Listen for future changes to item selection. * @return Function used to deregister listener */ listen(listener) { this._listeners.push(listener); return () => { this._listeners = this._listeners.filter((registered) => { return listener !== registered; }); }; } ngOnDestroy() { this._listeners = []; } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: UniqueSelectionDispatcher, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); } static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: UniqueSelectionDispatcher, providedIn: 'root' }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: UniqueSelectionDispatcher, decorators: [{ type: Injectable, args: [{ providedIn: 'root' }] }] }); //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidW5pcXVlLXNlbGVjdGlvbi1kaXNwYXRjaGVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vc3JjL2Nkay9jb2xsZWN0aW9ucy91bmlxdWUtc2VsZWN0aW9uLWRpc3BhdGNoZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7OztHQU1HO0FBRUgsT0FBTyxFQUFDLFVBQVUsRUFBWSxNQUFNLGVBQ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