Skip to content

Commit

Permalink
Fix emmiter return type for trigger
Browse files Browse the repository at this point in the history
commit_hash:00ea7605601adec011af5e598e643f46ee2bfedf
  • Loading branch information
sabio committed Nov 6, 2024
1 parent c4d4590 commit cf3652a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/utils/events/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Observer, observer, Listener } from './observer';
export type Emitter<T, U> = {
on: (a: string[], listener: Listener<T, U>) => Emitter<T, U>;
off: (a: string[], listener: Listener<T, U>) => Emitter<T, U>;
trigger: (a: string, d?: any) => any[];
trigger: (a: string, d?: T) => U[];
};

export const emitter = <T, U>(ctx: Window): Emitter<T, U> => {
Expand Down Expand Up @@ -34,6 +34,7 @@ export const emitter = <T, U>(ctx: Window): Emitter<T, U> => {
ctx,
`e.${eventName}`,
observers[eventName].trigger,
[],
)(event)
: [],
};
Expand Down
15 changes: 8 additions & 7 deletions src/utils/iframeConnector/iframeConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
MessageHandler,
MessageMeta,
IframeConnector,
MessageData,
} from './types';

import {
Expand Down Expand Up @@ -246,7 +247,7 @@ export const handleInputMessage = (
]);
const normResp = cMap(
pipe(firstArg, ctxMix(counterInfo)),
resp.concat([{}]),
resp.concat([undefined]),
);
const data = serialize(
[dateInfo, key, message[IFRAME_MESSAGE_COUNTER_ID]!],
Expand All @@ -273,10 +274,7 @@ export const handleInputMessage = (
}
}
};
const safeHandleInputMessage: typeof handleInputMessage = ctxErrorLogger(
's.fh',
handleInputMessage,
);
const safeHandleInputMessage = ctxErrorLogger('s.fh', handleInputMessage);

export const iframeConnector = (
ctx: Window,
Expand Down Expand Up @@ -330,7 +328,10 @@ export const iframeConnector = (
type: INIT_MESSAGE_CHILD,
},
(e, data) => {
emitterObj.trigger(INIT_MESSAGE_PARENT, [e, data]);
emitterObj.trigger(INIT_MESSAGE_PARENT, [
e,
data as MessageData,
]);
},
);
}, iframeList);
Expand All @@ -342,7 +343,7 @@ export const iframeConnector = (
type: INIT_MESSAGE_PARENT,
},
(e, data) => {
emitterObj.trigger(INIT_MESSAGE, [e, data]);
emitterObj.trigger(INIT_MESSAGE, [e, data as MessageData]);
},
);
}
Expand Down
5 changes: 4 additions & 1 deletion src/utils/iframeConnector/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ export type Message = {
string: string;
};

export type MessageHandler = (e: Event, ...data: Record<string, any>[]) => void;
export type MessageHandler = (
e: MessageEvent,
...data: Record<string, unknown>[]
) => void;

export type EventInfo = [MessageEvent, MessageData];

Expand Down

0 comments on commit cf3652a

Please sign in to comment.