[createReactClass] Remove createReactClass from CameraRollView - #21619
[createReactClass] Remove createReactClass from CameraRollView#21619exced wants to merge 6 commits into
Conversation
RSNara
left a comment
There was a problem hiding this comment.
Looks mostly good, but we have a few problems with our flow types.
| } | ||
|
|
||
| _fetch: async function(clear?: boolean) { | ||
| _fetch = async (clear?: boolean) => { |
There was a problem hiding this comment.
This doesn't need to be bound:
async _fetch(clear?: boolean) {| * A function that takes a single image as a parameter and renders it. | ||
| */ | ||
| renderImage: PropTypes.func, | ||
| renderImage: $FlowFixMe => React.Node, |
There was a problem hiding this comment.
this._fetch calls CameraRoll.getPhotos and then calls this._appendAssets after waiting for the CameraRoll.getPhotos promise to resolve. this._appendAssets groups the result into rows, and passes the rows to the data source this._ds. This eventually calls this._renderRow, which calls this._renderImage. So, we can actually figure out what this type is, and remove this $FlowFixMe.
CameraRoll.getPhotos contains the type information. (I think we should export it, if necessary).
| rowID: string, | ||
| ) { | ||
| var images = rowData.map(image => { | ||
| _renderRow = (rowData: Array<Image>, sectionID: string, rowID: string) => { |
There was a problem hiding this comment.
rowData isn't an array of Image components.
| } | ||
|
|
||
| _rowHasChanged: function(r1: Array<Image>, r2: Array<Image>): boolean { | ||
| _rowHasChanged(r1: Array<Image>, r2: Array<Image>): boolean { |
There was a problem hiding this comment.
Also, this doesn't have to be a method on the component class.
| var newState: Object = {loadingMore: false}; | ||
| _appendAssets = (data: Object) => { | ||
| const assets = data.edges; | ||
| const newState: Object = {loadingMore: false}; |
There was a problem hiding this comment.
const newState: $Shape<State> = { loadingMore: false };| import type {RNTesterProps} from 'RNTesterTypes'; | ||
|
|
||
| type Props = $ReadOnly<{| | ||
| ...RNTesterProps, |
There was a problem hiding this comment.
How come you're spreading the RNTesterProps into Props?
| _appendAssets: function(data: Object) { | ||
| var assets = data.edges; | ||
| var newState: Object = {loadingMore: false}; | ||
| _appendAssets = (data: Object) => { |
|
@RSNara I updated type definitions and get rid of $FlowFixMe, I indeed had to export types from CameraRoll, what do you think ? |
…o cameraRollView
RSNara
left a comment
There was a problem hiding this comment.
Almost there, but I realized that we have a lot of $FlowFixMes in this file, which is really bad since they can suppress valid flow/js errors. I think, where possible, we should try to get rid of them, because they make flow less likely to catch errors.
| rendererChanged() { | ||
| const ds = new ListView.DataSource({rowHasChanged: rowHasChanged}); | ||
| this.state.dataSource = ds.cloneWithRows( | ||
| // $FlowFixMe(>=0.41.0) |
There was a problem hiding this comment.
I think the general rule of thumb should be: If you see a $FlowFixMe, try to see if you can remove it.
Pretty sure this is suppressing some valid flow errors. For example, rowHasChanged takes an array of Image components, but this.state.assets is of type Array<GetPhotosEdge>.
| * found when Flow v0.68 was deployed. To see the error delete this comment | ||
| * and run Flow. */ | ||
| UNSAFE_componentWillReceiveProps: function(nextProps: {groupTypes?: string}) { | ||
| UNSAFE_componentWillReceiveProps(nextProps: {groupTypes?: string}) { |
There was a problem hiding this comment.
Can we remove this $FlowFixMe?
There was a problem hiding this comment.
Not sure how we can remove it properly though.
This is the Flow error I get :
Cannot extend property Component [1] with CameraRollView because property groupTypes is read-only in object type [2] but writable in object type [3] in the first argument of property UNSAFE_componentWillReceiveProps.
| heading?: number, | ||
| speed?: number, | ||
| }, | ||
| export type GetPhotosEdge = { |
There was a problem hiding this comment.
What do you think about renaming this to:
export type PhotoIdentifierObject = {Or:
export type PhotoIdentifier = {| }, | ||
| }; | ||
|
|
||
| export type GetPhotosReturn = { |
There was a problem hiding this comment.
What do you think about renaming this to:
export type PhotoIdentifierObjectsPage = {Or:
export type PhotoIdentifiersPage = {|
@RSNara I got rid of every $FlowFixMe, I don't really like the PropsObject type but I think it works |
facebook-github-bot
left a comment
There was a problem hiding this comment.
RSNara has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
|
The Props "sub" type representation, the actual prop types object (wrapped by $ReadOnly<>) |
|
Ah, that was no biggie. I fixed that on my end. 😁 |
|
Closing manually since this has been merged. |
Related to #21581
Remove createReactClass from CameraRollView.
Test Plan:
Release Notes:
[GENERAL] [ENHANCEMENT] [CameraRollView.js] - rm createReactClass