MCPcopy
hub / github.com/facebook/react / importFile

Function importFile

packages/react-devtools-timeline/src/timelineCache.js:50–110  ·  view source on GitHub ↗
(file: File)

Source from the content-addressed store, hash-verified

48}
49
50export function importFile(file: File): TimelineData | Error {
51 const fileName = file.name;
52 let record = fileNameToProfilerDataMap.get(fileName);
53
54 if (!record) {
55 const callbacks = new Set<(value: any) => mixed>();
56 const rejectCallbacks = new Set<(reason: mixed) => mixed>();
57 const thenable: Thenable<TimelineData> = {
58 status: 'pending',
59 value: null,
60 reason: null,
61 then(callback: (value: any) => mixed, reject: (error: mixed) => mixed) {
62 callbacks.add(callback);
63 rejectCallbacks.add(reject);
64 },
65
66 // Optional property used by Timeline:
67 displayName: `Importing file "${fileName}"`,
68 };
69
70 const wake = () => {
71 // This assumes they won't throw.
72 callbacks.forEach(callback => callback((thenable: any).value));
73 callbacks.clear();
74 rejectCallbacks.clear();
75 };
76 const wakeRejections = () => {
77 // This assumes they won't throw.
78 rejectCallbacks.forEach(callback => callback((thenable: any).reason));
79 rejectCallbacks.clear();
80 callbacks.clear();
81 };
82
83 record = thenable;
84
85 importFileWorker(file).then(data => {
86 switch (data.status) {
87 case 'SUCCESS':
88 const fulfilledThenable: FulfilledThenable<TimelineData> =
89 (thenable: any);
90 fulfilledThenable.status = 'fulfilled';
91 fulfilledThenable.value = data.processedData;
92 wake();
93 break;
94 case 'INVALID_PROFILE_ERROR':
95 case 'UNEXPECTED_ERROR':
96 const rejectedThenable: RejectedThenable<TimelineData> =
97 (thenable: any);
98 rejectedThenable.status = 'rejected';
99 rejectedThenable.reason = data.error;
100 wakeRejections();
101 break;
102 }
103 });
104
105 fileNameToProfilerDataMap.set(fileName, record);
106 }
107

Callers 1

Timeline.jsFile · 0.90

Calls 6

setMethod · 0.80
wakeFunction · 0.70
wakeRejectionsFunction · 0.70
readRecordFunction · 0.70
getMethod · 0.65
thenMethod · 0.65

Tested by

no test coverage detected