[6a3a178] | 1 | /**
|
---|
| 2 | * @license
|
---|
| 3 | * Copyright Google LLC All Rights Reserved.
|
---|
| 4 | *
|
---|
| 5 | * Use of this source code is governed by an MIT-style license that can be
|
---|
| 6 | * found in the LICENSE file at https://angular.io/license
|
---|
| 7 | */
|
---|
| 8 | import { Injectable } from '@angular/core';
|
---|
| 9 | import * as i0 from "@angular/core";
|
---|
| 10 | /**
|
---|
| 11 | * Class to coordinate unique selection based on name.
|
---|
| 12 | * Intended to be consumed as an Angular service.
|
---|
| 13 | * This service is needed because native radio change events are only fired on the item currently
|
---|
| 14 | * being selected, and we still need to uncheck the previous selection.
|
---|
| 15 | *
|
---|
| 16 | * This service does not *store* any IDs and names because they may change at any time, so it is
|
---|
| 17 | * less error-prone if they are simply passed through when the events occur.
|
---|
| 18 | */
|
---|
| 19 | export class UniqueSelectionDispatcher {
|
---|
| 20 | constructor() {
|
---|
| 21 | this._listeners = [];
|
---|
| 22 | }
|
---|
| 23 | /**
|
---|
| 24 | * Notify other items that selection for the given name has been set.
|
---|
| 25 | * @param id ID of the item.
|
---|
| 26 | * @param name Name of the item.
|
---|
| 27 | */
|
---|
| 28 | notify(id, name) {
|
---|
| 29 | for (let listener of this._listeners) {
|
---|
| 30 | listener(id, name);
|
---|
| 31 | }
|
---|
| 32 | }
|
---|
| 33 | /**
|
---|
| 34 | * Listen for future changes to item selection.
|
---|
| 35 | * @return Function used to deregister listener
|
---|
| 36 | */
|
---|
| 37 | listen(listener) {
|
---|
| 38 | this._listeners.push(listener);
|
---|
| 39 | return () => {
|
---|
| 40 | this._listeners = this._listeners.filter((registered) => {
|
---|
| 41 | return listener !== registered;
|
---|
| 42 | });
|
---|
| 43 | };
|
---|
| 44 | }
|
---|
| 45 | ngOnDestroy() {
|
---|
| 46 | this._listeners = [];
|
---|
| 47 | }
|
---|
| 48 | }
|
---|
| 49 | UniqueSelectionDispatcher.ɵprov = i0.ɵɵdefineInjectable({ factory: function UniqueSelectionDispatcher_Factory() { return new UniqueSelectionDispatcher(); }, token: UniqueSelectionDispatcher, providedIn: "root" });
|
---|
| 50 | UniqueSelectionDispatcher.decorators = [
|
---|
| 51 | { type: Injectable, args: [{ providedIn: 'root' },] }
|
---|
| 52 | ];
|
---|
| 53 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidW5pcXVlLXNlbGVjdGlvbi1kaXNwYXRjaGVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vc3JjL2Nkay9jb2xsZWN0aW9ucy91bmlxdWUtc2VsZWN0aW9uLWRpc3BhdGNoZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7OztHQU1HO0FBRUgsT0FBTyxFQUFDLFVBQVUsRUFBWSxNQUFNLGVBQWUsQ0FBQzs7QUFNcEQ7Ozs7Ozs7O0dBUUc7QUFFSCxNQUFNLE9BQU8seUJBQXlCO0lBRHRDO1FBRVUsZUFBVSxHQUF3QyxFQUFFLENBQUM7S0E2QjlEO0lBM0JDOzs7O09BSUc7SUFDSCxNQUFNLENBQUMsRUFBVSxFQUFFLElBQVk7UUFDN0IsS0FBSyxJQUFJLFFBQVEsSUFBSSxJQUFJLENBQUMsVUFBVSxFQUFFO1lBQ3BDLFFBQVEsQ0FBQyxFQUFFLEVBQUUsSUFBSSxDQUFDLENBQUM7U0FDcEI7SUFDSCxDQUFDO0lBRUQ7OztPQUdHO0lBQ0gsTUFBTSxDQUFDLFFBQTJDO1FBQ2hELElBQUksQ0FBQyxVQUFVLENBQUMsSUFBSSxDQUFDLFFBQVEsQ0FBQyxDQUFDO1FBQy9CLE9BQU8sR0FBRyxFQUFFO1lBQ1YsSUFBSSxDQUFDLFVBQVUsR0FBRyxJQUFJLENBQUMsVUFBVSxDQUFDLE1BQU0sQ0FBQyxDQUFDLFVBQTZDLEVBQUUsRUFBRTtnQkFDekYsT0FBTyxRQUFRLEtBQUssVUFBVS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