Skip to content

Commit 4fb49e5

Browse files
[FSSDK-12115] review update
1 parent 8b80447 commit 4fb49e5

File tree

2 files changed

+15
-21
lines changed

2 files changed

+15
-21
lines changed

lib/core/notification_center/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
import { LogHandler, ErrorHandler } from '../../modules/logging';
1717
import { objectValues } from '../../utils/fns';
18-
import { NotificationListener, NotificationPayloadMap } from '../../shared_types';
18+
import { ListenerPayload, NotificationListener, NotificationPayloadMap } from '../../shared_types';
1919

2020
import {
2121
LOG_LEVEL,
@@ -80,9 +80,9 @@ export class NotificationCenter {
8080
* can happen if the first argument is not a valid notification type, or if the same callback
8181
* function was already added as a listener by a prior call to this function.
8282
*/
83-
addNotificationListener<K extends keyof NotificationPayloadMap>(
84-
notificationType: K,
85-
callback: NotificationListener<NotificationPayloadMap[K]>
83+
addNotificationListener<T extends ListenerPayload>(
84+
notificationType: string,
85+
callback: NotificationListener<T>
8686
): number {
8787
try {
8888
const notificationTypeValues: string[] = objectValues(NOTIFICATION_TYPES);
@@ -202,9 +202,9 @@ export class NotificationCenter {
202202
* @param {string} notificationType One of NOTIFICATION_TYPES
203203
* @param {Object} notificationData Will be passed to callbacks called
204204
*/
205-
sendNotifications<K extends keyof NotificationPayloadMap>(
206-
notificationType: K,
207-
notificationData?: NotificationPayloadMap[K]
205+
sendNotifications<T extends ListenerPayload>(
206+
notificationType: string,
207+
notificationData?: T
208208
): void {
209209
try {
210210
(this.notificationListeners[notificationType] || []).forEach(

lib/shared_types.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,7 @@ export interface ListenerPayload {
120120
attributes?: UserAttributes;
121121
}
122122

123-
export type DecisionNotificationType =
124-
| typeof DECISION_NOTIFICATION_TYPES.AB_TEST
125-
| typeof DECISION_NOTIFICATION_TYPES.FEATURE
126-
| typeof DECISION_NOTIFICATION_TYPES.FEATURE_TEST
127-
| typeof DECISION_NOTIFICATION_TYPES.FEATURE_VARIABLE
128-
| typeof DECISION_NOTIFICATION_TYPES.ALL_FEATURE_VARIABLES
129-
| typeof DECISION_NOTIFICATION_TYPES.FLAG;
123+
export type DecisionNotificationType = typeof DECISION_NOTIFICATION_TYPES[keyof typeof DECISION_NOTIFICATION_TYPES];
130124

131125
export type DecisionSource =
132126
| typeof DECISION_SOURCES.FEATURE_TEST
@@ -215,11 +209,11 @@ export type NotificationPayloadMap = {
215209
[NOTIFICATION_TYPES.OPTIMIZELY_CONFIG_UPDATE]: undefined;
216210
};
217211

218-
export type NotificationListener<T> = (notificationData: T) => void;
212+
export type NotificationListener<T extends ListenerPayload> = (notificationData: T) => void;
219213
export interface NotificationCenter {
220-
addNotificationListener<K extends keyof NotificationPayloadMap>(
221-
notificationType: K,
222-
callback: NotificationListener<NotificationPayloadMap[K]>
214+
addNotificationListener<T extends ListenerPayload>(
215+
notificationType: string,
216+
callback: NotificationListener<T>
223217
): number;
224218
removeNotificationListener(listenerId: number): boolean;
225219
clearAllNotificationListeners(): void;
@@ -478,14 +472,14 @@ export interface Client {
478472
}
479473

480474
export interface ActivateListenerPayload extends ListenerPayload {
481-
experiment?: import('./shared_types').Experiment;
482-
variation?: import('./shared_types').Variation;
475+
experiment: import('./shared_types').Experiment;
476+
variation: import('./shared_types').Variation;
483477
logEvent: Event;
484478
}
485479

486480
export interface TrackListenerPayload extends ListenerPayload {
487481
eventKey: string;
488-
eventTags?: EventTags;
482+
eventTags: EventTags;
489483
logEvent: Event;
490484
}
491485

0 commit comments

Comments
 (0)