unique-selection-dispatcher-DtHZDqyJ.mjs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import * as i0 from '@angular/core';
  2. import { Injectable } from '@angular/core';
  3. /**
  4. * Class to coordinate unique selection based on name.
  5. * Intended to be consumed as an Angular service.
  6. * This service is needed because native radio change events are only fired on the item currently
  7. * being selected, and we still need to uncheck the previous selection.
  8. *
  9. * This service does not *store* any IDs and names because they may change at any time, so it is
  10. * less error-prone if they are simply passed through when the events occur.
  11. */
  12. class UniqueSelectionDispatcher {
  13. _listeners = [];
  14. /**
  15. * Notify other items that selection for the given name has been set.
  16. * @param id ID of the item.
  17. * @param name Name of the item.
  18. */
  19. notify(id, name) {
  20. for (let listener of this._listeners) {
  21. listener(id, name);
  22. }
  23. }
  24. /**
  25. * Listen for future changes to item selection.
  26. * @return Function used to deregister listener
  27. */
  28. listen(listener) {
  29. this._listeners.push(listener);
  30. return () => {
  31. this._listeners = this._listeners.filter((registered) => {
  32. return listener !== registered;
  33. });
  34. };
  35. }
  36. ngOnDestroy() {
  37. this._listeners = [];
  38. }
  39. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: UniqueSelectionDispatcher, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
  40. static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: UniqueSelectionDispatcher, providedIn: 'root' });
  41. }
  42. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: UniqueSelectionDispatcher, decorators: [{
  43. type: Injectable,
  44. args: [{ providedIn: 'root' }]
  45. }] });
  46. export { UniqueSelectionDispatcher as U };
  47. //# sourceMappingURL=unique-selection-dispatcher-DtHZDqyJ.mjs.map