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:
@@ -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) => {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user