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