Skip to content

Commit 0715bc6

Browse files
authored
chore: convert codebase to TS (#215)
Converts the whole codebase, including the example to TS. Fixes #202
1 parent 18389c2 commit 0715bc6

File tree

130 files changed

+15511
-31760
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+15511
-31760
lines changed

.babelrc

Lines changed: 0 additions & 4 deletions
This file was deleted.

.circleci/config.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,19 @@ jobs:
1515
- run:
1616
working_directory: ~/rgommezz/react-native-offline
1717
command: nvm install 9.10.0 && nvm alias default 9.10.0
18+
- run: npm i
1819
# Restore the dependency cache
1920
- restore_cache:
2021
keys:
2122
# This branch if available
22-
- v1-dep-{{ .Branch }}-
23+
- v3-dep-{{ .Branch }}-
2324
# Default branch if not
24-
- v1-dep-master-
25+
- v3-dep-master-
2526
# Any branch if there are none on the default branch - this should be unnecessary if you have your default branch configured correctly
26-
- v1-dep-
27+
- v3-dep-
2728
# Save dependency cache
2829
- save_cache:
29-
key: v1-dep-{{ .Branch }}-{{ epoch }}
30+
key: v3-dep-{{ .Branch }}-{{ epoch }}
3031
paths:
3132
# This is a broad list of cache paths to include many possible development environments
3233
# You can probably delete some of these entries
@@ -41,6 +42,7 @@ jobs:
4142
- ./node_modules
4243
# Test
4344
- run: npm run lint
45+
- run: npm run ts
4446
- run: npm run test:coverage
4547
# Teardown
4648
# Save test results

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules/
22
coverage/
33
flow-typed/
4+
test/__snapshots__/

.eslintrc

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
{
22
"extends": [
33
"airbnb",
4-
"plugin:flowtype/recommended",
4+
"plugin:@typescript-eslint/recommended",
55
"plugin:react/recommended",
66
"prettier",
7-
"prettier/flowtype",
8-
"prettier/react"
9-
],
10-
"parser": "babel-eslint",
11-
"plugins": [
12-
"flowtype",
13-
"react",
14-
"prettier"
7+
"prettier/react",
8+
"prettier/@typescript-eslint"
159
],
10+
"settings": {
11+
"import/resolver": {
12+
"node": {
13+
"extensions": [".js", ".jsx", ".ts", ".tsx"]
14+
}
15+
}
16+
},
17+
"parser": "@typescript-eslint/parser",
18+
"plugins": ["react", "@typescript-eslint", "prettier"],
1619
"parserOptions": {
1720
"ecmaVersion": 6,
1821
"sourceType": "module",
@@ -37,28 +40,18 @@
3740
"import/extensions": 0,
3841
"no-use-before-define": 0,
3942
"import/no-extraneous-dependencies": 0,
43+
"import/prefer-default-export": 0,
4044
"global-require": 0,
4145
"prefer-promise-reject-errors": 0,
4246
"react/prop-types": 0,
43-
"react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
47+
"react/jsx-filename-extension": 0,
4448
"react/require-default-props": 0,
45-
"flowtype/boolean-style": [
46-
2,
47-
"boolean"
48-
],
49-
"flowtype/no-weak-types": 1,
50-
"flowtype/require-parameter-type": 0,
51-
"flowtype/require-return-type": [
52-
0,
53-
"always",
54-
{
55-
"annotateUndefined": "never"
56-
}
57-
],
58-
"flowtype/require-valid-file-annotation": 2,
59-
"flowtype/use-flow-type": 1,
60-
"flowtype/valid-syntax": 1,
61-
"react/display-name": 0
49+
"react/display-name": 0,
50+
"react/destructuring-assignment": 0,
51+
"@typescript-eslint/no-use-before-define": 0,
52+
"no-return-assign": 0,
53+
"no-undef": 0,
54+
"@typescript-eslint/ban-ts-ignore": 1
6255
},
6356
"globals": {
6457
"jest": true

.flowconfig

Lines changed: 0 additions & 95 deletions
This file was deleted.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ npm-debug.log
44

55
#jest
66
coverage/
7+
.jest/
8+
dist/
79

810
# OSX
911
#

.prettierrc.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"trailingComma": "all",
3+
"tabWidth": 2,
4+
"semi": true,
5+
"singleQuote": true
6+
}
File renamed without changes.

babel.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
presets: ["module:metro-react-native-babel-preset"]
3+
};

example/App.js renamed to example/App.tsx

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
import React from 'react';
22
import { Platform, StatusBar, StyleSheet, View } from 'react-native';
3-
import { AppLoading, Font, Icon } from 'expo';
3+
import { Ionicons } from '@expo/vector-icons';
4+
import * as Font from 'expo-font';
45
import AppNavigator from './navigation/AppNavigator';
56
import DummyNetworkContext from './DummyNetworkContext';
67

78
const onlineUrl = 'https://www.google.com/';
89
const offlineUrl = 'https://www.weifhweopfhwioehfiwoephfpweoifhewifhpewoif.com';
10+
interface Props {
11+
skipLoadingScreen?: boolean;
12+
}
913

10-
export default class App extends React.Component {
11-
constructor(props) {
14+
interface State {
15+
isLoadingComplete: boolean;
16+
network: {
17+
pingUrl: string;
18+
toggleConnection: () => void;
19+
};
20+
}
21+
export default class App extends React.Component<Props, State> {
22+
constructor(props: Props) {
1223
super(props);
1324
this.state = {
1425
isLoadingComplete: false,
@@ -19,6 +30,14 @@ export default class App extends React.Component {
1930
};
2031
}
2132

33+
async componentDidMount() {
34+
await Font.loadAsync({
35+
...Ionicons.font,
36+
'space-mono': require('./assets/fonts/SpaceMono-Regular.ttf'),
37+
});
38+
this.setState({ isLoadingComplete: true });
39+
}
40+
2241
toggleConnection = () => {
2342
this.setState(prevState => ({
2443
network: {
@@ -29,26 +48,11 @@ export default class App extends React.Component {
2948
}));
3049
};
3150

32-
loadResourcesAsync = async () =>
33-
Font.loadAsync({
34-
...Icon.Ionicons.font,
35-
'space-mono': require('./assets/fonts/SpaceMono-Regular.ttf'),
36-
});
37-
38-
handleFinishLoading = () => {
39-
this.setState({ isLoadingComplete: true });
40-
};
41-
4251
render() {
4352
const { isLoadingComplete, network } = this.state;
4453
const { skipLoadingScreen } = this.props;
4554
if (!isLoadingComplete && !skipLoadingScreen) {
46-
return (
47-
<AppLoading
48-
startAsync={this.loadResourcesAsync}
49-
onFinish={this.handleFinishLoading}
50-
/>
51-
);
55+
return null;
5256
}
5357
return (
5458
<DummyNetworkContext.Provider value={network}>

0 commit comments

Comments
 (0)