forked from facebook/react
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Import Prep][4/n] Fix Flow errors (#133)
Summary === 1. Fix some errors manually 1. Copy some updated ContextMenu code from original React sources Resolves #38. Test Plan === 1. `yarn flow`: No errors 1. `yarn lint` 1. `yarn test` 1. `yarn start`: Everything still works, especially the context menu.
- Loading branch information
Showing
6 changed files
with
60 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,29 @@ | ||
// @flow | ||
|
||
export const readInputData = (file: File) => { | ||
import nullthrows from 'nullthrows'; | ||
|
||
export const readInputData = (file: File): Promise<string> => { | ||
if (!file.name.endsWith('.json')) { | ||
console.error( | ||
'Invalid file type, insert a captured performance profile JSON', | ||
return Promise.reject( | ||
new Error( | ||
'Invalid file type. Only JSON performance profiles are supported', | ||
), | ||
); | ||
return; | ||
} | ||
// Initialize file reader | ||
|
||
const fileReader = new FileReader(); | ||
|
||
return new Promise((resolve, reject) => { | ||
fileReader.onerror = () => { | ||
fileReader.abort(); | ||
reject(new DOMException('Problem parsing input file.')); | ||
}; | ||
|
||
fileReader.onload = () => { | ||
resolve(fileReader.result); | ||
const result = nullthrows(fileReader.result); | ||
if (typeof result === 'string') { | ||
resolve(result); | ||
} | ||
reject(new Error('Input file was not read as a string')); | ||
}; | ||
|
||
fileReader.onerror = () => reject(fileReader.error); | ||
|
||
fileReader.readAsText(file); | ||
}); | ||
}; |