main
ts 83 lines 2.47 KB
Raw
1 /**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 export type MessagePayload =
9 | null
10 | string
11 | number
12 | boolean
13 | {[key: string]: MessagePayload}
14 | MessagePayload[];
15 export type Message = {event: string; payload?: MessagePayload};
16
17 export type WallListener = (message: unknown) => void;
18 export type Wall = {
19 listen: (fn: WallListener) => () => void;
20 send: (event: string, payload?: MessagePayload) => void;
21 };
22
23 export type Bridge = {
24 addListener(event: string, listener: (params: unknown) => unknown): void;
25 removeListener(event: string, listener: Function): void;
26 shutdown: () => void;
27 };
28 export type Store = Object;
29 export type BrowserTheme = 'dark' | 'light';
30 export type Config = {
31 supportsReloadAndProfile?: boolean;
32 };
33
34 export function createBridge(wall: Wall): Bridge;
35 export function createStore(bridge: Bridge, config?: Config): Store;
36
37 export type ReactFunctionLocation = [
38 string, // function name
39 string, // file name TODO: model nested eval locations as nested arrays
40 number, // enclosing line number
41 number, // enclosing column number
42 ];
43 export type ReactCallSite = [
44 string, // function name
45 string, // file name TODO: model nested eval locations as nested arrays
46 number, // line number
47 number, // column number
48 number, // enclosing line number
49 number, // enclosing column number
50 boolean, // async resume
51 ];
52 export type ViewElementSource = (
53 source: ReactFunctionLocation | ReactCallSite,
54 symbolicatedSource: ReactFunctionLocation | ReactCallSite | null,
55 ) => void;
56 export type ViewAttributeSource = (
57 id: number,
58 path: Array<string | number>,
59 ) => void;
60 export type CanViewElementSource = (
61 source: ReactFunctionLocation | ReactCallSite,
62 symbolicatedSource: ReactFunctionLocation | ReactCallSite | null,
63 ) => boolean;
64 export type FetchFileWithCaching = (url: string) => Promise<string>;
65
66 export type InitializationOptions = {
67 bridge: Bridge;
68 store: Store;
69 theme?: BrowserTheme;
70 viewAttributeSourceFunction?: ViewAttributeSource;
71 viewElementSourceFunction?: ViewElementSource;
72 canViewElementSourceFunction?: CanViewElementSource;
73 fetchFileWithCaching?: FetchFileWithCaching;
74 };
75
76 export function initializeComponents(
77 node: Element | Document,
78 options: InitializationOptions,
79 ): void;
80 export function initializeProfiler(
81 node: Element | Document,
82 options: InitializationOptions,
83 ): void;