( element: Element, hooksTree: HooksTree, loadHookNamesFunction: LoadHookNamesFunction, fetchFileWithCaching: FetchFileWithCaching | null, )
| 73 | } |
| 74 | |
| 75 | export function loadHookNames( |
| 76 | element: Element, |
| 77 | hooksTree: HooksTree, |
| 78 | loadHookNamesFunction: LoadHookNamesFunction, |
| 79 | fetchFileWithCaching: FetchFileWithCaching | null, |
| 80 | ): HookNames | null { |
| 81 | let record = map.get(element); |
| 82 | |
| 83 | if (__DEBUG__) { |
| 84 | console.groupCollapsed('loadHookNames() record:'); |
| 85 | console.log(record); |
| 86 | console.groupEnd(); |
| 87 | } |
| 88 | |
| 89 | if (!record) { |
| 90 | const callbacks = new Set<(value: any) => mixed>(); |
| 91 | const rejectCallbacks = new Set<(reason: mixed) => mixed>(); |
| 92 | const thenable: Thenable<HookNames> = { |
| 93 | status: 'pending', |
| 94 | value: null, |
| 95 | reason: null, |
| 96 | then(callback: (value: any) => mixed, reject: (error: mixed) => mixed) { |
| 97 | callbacks.add(callback); |
| 98 | rejectCallbacks.add(reject); |
| 99 | }, |
| 100 | |
| 101 | // Optional property used by Timeline: |
| 102 | displayName: `Loading hook names for ${element.displayName || 'Unknown'}`, |
| 103 | }; |
| 104 | |
| 105 | let timeoutID: $FlowFixMe | null; |
| 106 | let didTimeout = false; |
| 107 | let status: 'success' | 'error' | 'timeout' | 'unknown' = 'unknown'; |
| 108 | let resolvedHookNames: HookNames | null = null; |
| 109 | |
| 110 | const wake = () => { |
| 111 | if (timeoutID) { |
| 112 | clearTimeout(timeoutID); |
| 113 | timeoutID = null; |
| 114 | } |
| 115 | |
| 116 | // This assumes they won't throw. |
| 117 | callbacks.forEach(callback => callback((thenable: any).value)); |
| 118 | callbacks.clear(); |
| 119 | rejectCallbacks.clear(); |
| 120 | }; |
| 121 | const wakeRejections = () => { |
| 122 | if (timeoutID) { |
| 123 | clearTimeout(timeoutID); |
| 124 | timeoutID = null; |
| 125 | } |
| 126 | // This assumes they won't throw. |
| 127 | rejectCallbacks.forEach(callback => callback((thenable: any).reason)); |
| 128 | rejectCallbacks.clear(); |
| 129 | callbacks.clear(); |
| 130 | }; |
| 131 | |
| 132 | const handleLoadComplete = (durationMs: number): void => { |
no test coverage detected