@angular/cdk
Version:
Angular Material Component Development Kit
1 lines • 3.22 kB
Source Map (JSON)
{"version":3,"file":"_unique-selection-dispatcher-chunk.mjs","sources":["../../../../../darwin_arm64-fastbuild-ST-fdfa778d11ba/bin/src/cdk/collections/unique-selection-dispatcher.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\n\nimport {Injectable, OnDestroy} from '@angular/core';\n\n// Users of the Dispatcher never need to see this type, but TypeScript requires it to be exported.\nexport type UniqueSelectionDispatcherListener = (id: string, name: string) => void;\n\n/**\n * Class to coordinate unique selection based on name.\n * Intended to be consumed as an Angular service.\n * This service is needed because native radio change events are only fired on the item currently\n * being selected, and we still need to uncheck the previous selection.\n *\n * This service does not *store* any IDs and names because they may change at any time, so it is\n * less error-prone if they are simply passed through when the events occur.\n */\n@Injectable({providedIn: 'root'})\nexport class UniqueSelectionDispatcher implements OnDestroy {\n private _listeners: UniqueSelectionDispatcherListener[] = [];\n\n /**\n * Notify other items that selection for the given name has been set.\n * @param id ID of the item.\n * @param name Name of the item.\n */\n notify(id: string, name: string) {\n for (let listener of this._listeners) {\n listener(id, name);\n }\n }\n\n /**\n * Listen for future changes to item selection.\n * @return Function used to deregister listener\n */\n listen(listener: UniqueSelectionDispatcherListener): () => void {\n this._listeners.push(listener);\n return () => {\n this._listeners = this._listeners.filter((registered: UniqueSelectionDispatcherListener) => {\n return listener !== registered;\n });\n };\n }\n\n ngOnDestroy() {\n this._listeners = [];\n }\n}\n"],"names":["UniqueSelectionDispatcher","_listeners","notify","id","name","listener","listen","push","filter","registered","ngOnDestroy","deps","target","i0","ɵɵFactoryTarget","Injectable","ɵprov","ɵɵngDeclareInjectable","minVersion","version","ngImport","type","decorators","providedIn"],"mappings":";;;MAuBaA,yBAAyB,CAAA;AAC5BC,EAAAA,UAAU,GAAwC,EAAE;AAO5DC,EAAAA,MAAMA,CAACC,EAAU,EAAEC,IAAY,EAAA;AAC7B,IAAA,KAAK,IAAIC,QAAQ,IAAI,IAAI,CAACJ,UAAU,EAAE;AACpCI,MAAAA,QAAQ,CAACF,EAAE,EAAEC,IAAI,CAAC;AACpB;AACF;EAMAE,MAAMA,CAACD,QAA2C,EAAA;AAChD,IAAA,IAAI,CAACJ,UAAU,CAACM,IAAI,CAACF,QAAQ,CAAC;AAC9B,IAAA,OAAO,MAAK;MACV,IAAI,CAACJ,UAAU,GAAG,IAAI,CAACA,UAAU,CAACO,MAAM,CAAEC,UAA6C,IAAI;QACzF,OAAOJ,QAAQ,KAAKI,UAAU;AAChC,OAAC,CAAC;KACH;AACH;AAEAC,EAAAA,WAAWA,GAAA;IACT,IAAI,CAACT,UAAU,GAAG,EAAE;AACtB;;;;;UA7BWD,yBAAyB;AAAAW,IAAAA,IAAA,EAAA,EAAA;AAAAC,IAAAA,MAAA,EAAAC,EAAA,CAAAC,eAAA,CAAAC;AAAA,GAAA,CAAA;AAAzB,EAAA,OAAAC,KAAA,GAAAH,EAAA,CAAAI,qBAAA,CAAA;AAAAC,IAAAA,UAAA,EAAA,QAAA;AAAAC,IAAAA,OAAA,EAAA,QAAA;AAAAC,IAAAA,QAAA,EAAAP,EAAA;AAAAQ,IAAAA,IAAA,EAAArB,yBAAyB;gBADb;AAAM,GAAA,CAAA;;;;;;QAClBA,yBAAyB;AAAAsB,EAAAA,UAAA,EAAA,CAAA;UADrCP,UAAU;WAAC;AAACQ,MAAAA,UAAU,EAAE;KAAO;;;;;;"}