Skip to content

Commit

Permalink
libdefs: Compose and use libdef for react-native-webview at 7.6.
Browse files Browse the repository at this point in the history
The latest version FlowTyped has a libdef for is 6, unfortunately.

Ah, well. This is a best effort at replicating the types at
`react-native-community/react-native-webview@c4001338c`, tagged as
v7.6.0, the latest 7.x.

One notable lack, here, was also present in the 5.x libdef from
FlowTyped, and I didn't find a good way to fix it. The `WebView`
props aren't exact, so, e.g., the failure to remove the `useWebKit`
prop in the RN 60 upgrade commit would not have been caught.

See the entry in `docs/howto/libdefs.md` added in this commit for
more detail.
  • Loading branch information
chrisbobbe committed Jun 3, 2020
1 parent 2db86bb commit 747145f
Show file tree
Hide file tree
Showing 4 changed files with 688 additions and 4 deletions.
1 change: 1 addition & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ node_modules/react-native/flow/
; where the opposite behavior is exhibited!)
flow-typed/@sentry/react-native_v1.x.x.js
flow-typed/@react-native-community/async-storage_v1.x.x.js
flow-typed/react-native-webview_v6.x.x.js


[strict]
Expand Down
53 changes: 52 additions & 1 deletion docs/howto/libdefs.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ dependencies well-typed.

-----

## `remotedev-serialize`

Some assembly was required for a libdef for `remotedev-serialize`, but
it was important to get one working [1]. Here's a summary of what that
was like.
Expand Down Expand Up @@ -90,4 +92,53 @@ was like.
[5]: https://github.com/zulip/zulip-mobile/issues/3458#issuecomment-542870835
[6]: https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/Android.20build.3A.20unimodules/near/845802
[7]: https://flow.org/en/docs/libdefs/creation/
[8]: https://github.com/flow-typed/flow-typed/blob/master/CONTRIBUTING.md#dont-import-types-from-other-libdefs
[8]: https://github.com/flow-typed/flow-typed/blob/master/CONTRIBUTING.md#dont-import-types-from-other-libdefs

## `react-native-webview` at v7.6

The latest version FlowTyped has a libdef for is 6, unfortunately.

Ah, well. I made a best effort at replicating the types at
`react-native-community/react-native-webview@c4001338c`, tagged as
v7.6.0, the latest 7.x.

I used FlowType's `react-native-webview` v6 libdef as a starting
point, to match any conventions that may have been established after
the v5 libdef we were on before. Then, I ran the following in the
`react-native-webview` repo, which I had cloned:

```bash
git diff v6.8.0..v7.6.0 -- src/WebViewTypes.ts
```

I then went through the diff and did my best to apply each change,
blending in with the local style. The most prominent example of this
blending in was using, e.g.,

```javascript
onHttpError?: WebViewHttpErrorEvent => mixed,
```

instead of

```javascript
onHttpError?: (event: WebViewHttpErrorEvent) => void,
```

which would be valid Flow but wouldn't blend in with similar event
handlers.

One choice that proved helpful was to *not* start at the top of the
diff and work my way down, but to find changes to the major types
that the Flow libdef needs to export, and start there, following
through with any changes to auxiliary types that those changes
depend on. There were many changes in the TypeScript that didn't
affect anything that our libdef exports, and these were rightfully
and automatically ignored with this approach, saving time.

Like with v5, though, the v6 libdef was lacking most of the JSDocs,
and several properties were needlessly in a different order than in
the TypeScript, so once I was basically familiar with the changes I
needed to take, I went through
`react-native-community/react-native-webview@c4001338c` and fixed
the ordering and copied over lots of comments.
Loading

0 comments on commit 747145f

Please sign in to comment.