mirror of
https://github.com/hexastack/hexabot
synced 2025-02-23 04:48:51 +00:00
fix: enhance typing
This commit is contained in:
parent
8ea4251bcf
commit
aebeeb1f59
@ -26,16 +26,24 @@ type BroadcastChannelPayload = {
|
||||
data?: string | number | boolean | Record<string, unknown> | undefined | null;
|
||||
};
|
||||
|
||||
export type BroadcastChannelData = {
|
||||
type BroadcastChannelData = {
|
||||
tabId: string;
|
||||
payload: BroadcastChannelPayload;
|
||||
};
|
||||
|
||||
export interface IBroadcastChannelProps {
|
||||
interface IBroadcastChannelProps {
|
||||
channelName: string;
|
||||
children: ReactNode;
|
||||
}
|
||||
|
||||
interface IBroadcastChannelContext {
|
||||
subscribe: (
|
||||
event: `${EBCEvent}`,
|
||||
callback: (message: BroadcastChannelData) => void,
|
||||
) => void;
|
||||
postMessage: (payload: BroadcastChannelPayload) => void;
|
||||
}
|
||||
|
||||
const getOrCreateTabId = () => {
|
||||
let storedTabId = sessionStorage.getItem("tab_uuid");
|
||||
|
||||
@ -49,14 +57,6 @@ const getOrCreateTabId = () => {
|
||||
return storedTabId;
|
||||
};
|
||||
|
||||
interface IBroadcastChannelContext {
|
||||
subscribe: (
|
||||
event: `${EBCEvent}`,
|
||||
callback: (message: BroadcastChannelData) => void,
|
||||
) => void;
|
||||
postMessage: (payload: BroadcastChannelPayload) => void;
|
||||
}
|
||||
|
||||
export const BroadcastChannelContext = createContext<
|
||||
IBroadcastChannelContext | undefined
|
||||
>(undefined);
|
||||
@ -69,7 +69,10 @@ export const BroadcastChannelProvider: FC<IBroadcastChannelProps> = ({
|
||||
new BroadcastChannel(channelName),
|
||||
);
|
||||
const subscribersRef = useRef<
|
||||
Record<string, Array<(message: BroadcastChannelData) => void>>
|
||||
Record<
|
||||
string,
|
||||
Array<Parameters<IBroadcastChannelContext["subscribe"]>["1"]>
|
||||
>
|
||||
>({});
|
||||
const tabUuid = getOrCreateTabId();
|
||||
|
||||
|
@ -26,16 +26,24 @@ type BroadcastChannelPayload = {
|
||||
data?: string | number | boolean | Record<string, unknown> | undefined | null;
|
||||
};
|
||||
|
||||
export type BroadcastChannelData = {
|
||||
type BroadcastChannelData = {
|
||||
tabId: string;
|
||||
payload: BroadcastChannelPayload;
|
||||
};
|
||||
|
||||
export interface IBroadcastChannelProps {
|
||||
interface IBroadcastChannelProps {
|
||||
channelName: string;
|
||||
children: ReactNode;
|
||||
}
|
||||
|
||||
interface IBroadcastChannelContext {
|
||||
subscribe: (
|
||||
event: `${EBCEvent}`,
|
||||
callback: (message: BroadcastChannelData) => void,
|
||||
) => void;
|
||||
postMessage: (payload: BroadcastChannelPayload) => void;
|
||||
}
|
||||
|
||||
const getOrCreateTabId = () => {
|
||||
let storedTabId = sessionStorage.getItem("tab_uuid");
|
||||
|
||||
@ -49,14 +57,6 @@ const getOrCreateTabId = () => {
|
||||
return storedTabId;
|
||||
};
|
||||
|
||||
interface IBroadcastChannelContext {
|
||||
subscribe: (
|
||||
event: `${EBCEvent}`,
|
||||
callback: (message: BroadcastChannelData) => void,
|
||||
) => void;
|
||||
postMessage: (payload: BroadcastChannelPayload) => void;
|
||||
}
|
||||
|
||||
export const BroadcastChannelContext = createContext<
|
||||
IBroadcastChannelContext | undefined
|
||||
>(undefined);
|
||||
@ -69,7 +69,10 @@ export const BroadcastChannelProvider: FC<IBroadcastChannelProps> = ({
|
||||
new BroadcastChannel(channelName),
|
||||
);
|
||||
const subscribersRef = useRef<
|
||||
Record<string, Array<(message: BroadcastChannelData) => void>>
|
||||
Record<
|
||||
string,
|
||||
Array<Parameters<IBroadcastChannelContext["subscribe"]>["1"]>
|
||||
>
|
||||
>({});
|
||||
const tabUuid = getOrCreateTabId();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user