Notifications: Prevent triggering duplicate notifications (#114497)

* fix(notifications): prevent event listener re-registration on route changes

* refactor(notifications): rename alert handling functions for clarity

* refactor(notifications): simplify alert handling by using spread operator for payloads

* refactor(events): address feedback - update LegacyEmitter and LegacyEventHandler interfaces for improved type safety

* fix(events): ensure event handlers handle undefined events gracefully in tests

* test(notifications): add tests for event listener registration and cleanup in AppNotificationList
This commit is contained in:
Alan Martin
2025-11-27 16:12:26 +00:00
committed by GitHub
parent f12cc5411d
commit ba58506ffd
4 changed files with 98 additions and 16 deletions
@@ -91,8 +91,10 @@ describe('EventBus', () => {
it('Supports legacy events', () => {
const bus = new EventBusSrv();
const events: LegacyEventPayload[] = [];
const handler = (event: LegacyEventPayload) => {
events.push(event);
const handler = (event?: LegacyEventPayload) => {
if (event) {
events.push(event);
}
};
bus.on(legacyEvent, handler);
@@ -111,7 +113,9 @@ describe('EventBus', () => {
const newEvents: AlertSuccessEvent[] = [];
bus.on(legacyEvent, (event) => {
legacyEvents.push(event);
if (event) {
legacyEvents.push(event);
}
});
bus.subscribe(AlertSuccessEvent, (event) => {
+2 -2
View File
@@ -133,12 +133,12 @@ export interface LegacyEmitter {
/**
* @deprecated use $on
*/
off<T>(event: AppEvent<T> | string, handler: (payload?: T) => void): void;
off<T>(event: AppEvent<T> | string, handler: LegacyEventHandler<T>): void;
}
/** @public */
export interface LegacyEventHandler<T> {
(payload: T): void;
(payload?: T): void;
wrapper?: (event: BusEvent) => void;
}