Skip to content

Commit 2113f1b

Browse files
committed
Fix errors reported by TSLint.
1 parent 8c186ff commit 2113f1b

File tree

6 files changed

+109
-101
lines changed

6 files changed

+109
-101
lines changed

Web/React/react-typescript-toolchain-2018-spring/src/App.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ import * as ReactDOM from 'react-dom';
33
import App from './App';
44

55
it('renders without crashing', () => {
6-
const div = document.createElement('div');
7-
ReactDOM.render(<App />, div);
6+
const div = document.createElement('div');
7+
ReactDOM.render(<App/>, div);
88
});
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
import * as React from 'react';
22
import './App.css';
33

4-
const logo = require('./logo.svg');
4+
import logo from './logo.svg';
55

66
class App extends React.Component {
7-
render() {
8-
return (
9-
<div className="App">
10-
<header className="App-header">
11-
<img src={logo} className="App-logo" alt="logo" />
12-
<h1 className="App-title">Welcome to React</h1>
13-
</header>
14-
<p className="App-intro">
15-
To get started, edit <code>src/App.tsx</code> and save to reload.
16-
</p>
17-
</div>
18-
);
19-
}
7+
public render() {
8+
return (
9+
<div className="App">
10+
<header className="App-header">
11+
<img src={logo} className="App-logo" alt="logo"/>
12+
<h1 className="App-title">Welcome to React</h1>
13+
</header>
14+
<p className="App-intro">
15+
To get started, edit <code>src/App.tsx</code> and save to reload.
16+
</p>
17+
</div>
18+
);
19+
}
2020
}
2121

2222
export default App;
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import * as React from 'react';
22
import * as ReactDOM from 'react-dom';
33
import App from './App';
4-
import registerServiceWorker from './registerServiceWorker';
54
import './index.css';
5+
import registerServiceWorker from './registerServiceWorker';
66

77
ReactDOM.render(
8-
<App />,
9-
document.getElementById('root') as HTMLElement
8+
<App/>,
9+
document.getElementById('root') as HTMLElement
1010
);
1111
registerServiceWorker();

Web/React/react-typescript-toolchain-2018-spring/src/registerServiceWorker.ts

Lines changed: 81 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -10,105 +10,105 @@
1010
// This link also includes instructions on opting out of this behavior.
1111

1212
const isLocalhost = Boolean(
13-
window.location.hostname === 'localhost' ||
13+
window.location.hostname === 'localhost' ||
1414
// [::1] is the IPv6 localhost address.
1515
window.location.hostname === '[::1]' ||
1616
// 127.0.0.1/8 is considered localhost for IPv4.
1717
window.location.hostname.match(
18-
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
18+
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
1919
)
2020
);
2121

2222
export default function register() {
23-
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
24-
// The URL constructor is available in all browsers that support SW.
25-
const publicUrl = new URL(
26-
process.env.PUBLIC_URL!,
27-
window.location.toString()
28-
);
29-
if (publicUrl.origin !== window.location.origin) {
30-
// Our service worker won't work if PUBLIC_URL is on a different origin
31-
// from what our page is served on. This might happen if a CDN is used to
32-
// serve assets; see https://github.com/facebookincubator/create-react-app/issues/2374
33-
return;
34-
}
23+
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
24+
// The URL constructor is available in all browsers that support SW.
25+
const publicUrl = new URL(
26+
process.env.PUBLIC_URL!,
27+
window.location.toString()
28+
);
29+
if (publicUrl.origin !== window.location.origin) {
30+
// Our service worker won't work if PUBLIC_URL is on a different origin
31+
// from what our page is served on. This might happen if a CDN is used to
32+
// serve assets; see https://github.com/facebookincubator/create-react-app/issues/2374
33+
return;
34+
}
3535

36-
window.addEventListener('load', () => {
37-
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
36+
window.addEventListener('load', () => {
37+
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
3838

39-
if (!isLocalhost) {
40-
// Is not local host. Just register service worker
41-
registerValidSW(swUrl);
42-
} else {
43-
// This is running on localhost. Lets check if a service worker still exists or not.
44-
checkValidServiceWorker(swUrl);
45-
}
46-
});
47-
}
39+
if (!isLocalhost) {
40+
// Is not local host. Just register service worker
41+
registerValidSW(swUrl);
42+
} else {
43+
// This is running on localhost. Lets check if a service worker still exists or not.
44+
checkValidServiceWorker(swUrl);
45+
}
46+
});
47+
}
4848
}
4949

5050
function registerValidSW(swUrl: string) {
51-
navigator.serviceWorker
52-
.register(swUrl)
53-
.then(registration => {
54-
registration.onupdatefound = () => {
55-
const installingWorker = registration.installing;
56-
if (installingWorker) {
57-
installingWorker.onstatechange = () => {
58-
if (installingWorker.state === 'installed') {
59-
if (navigator.serviceWorker.controller) {
60-
// At this point, the old content will have been purged and
61-
// the fresh content will have been added to the cache.
62-
// It's the perfect time to display a 'New content is
63-
// available; please refresh.' message in your web app.
64-
console.log('New content is available; please refresh.');
65-
} else {
66-
// At this point, everything has been precached.
67-
// It's the perfect time to display a
68-
// 'Content is cached for offline use.' message.
69-
console.log('Content is cached for offline use.');
70-
}
71-
}
72-
};
73-
}
74-
};
75-
})
76-
.catch(error => {
77-
console.error('Error during service worker registration:', error);
78-
});
51+
navigator.serviceWorker
52+
.register(swUrl)
53+
.then((registration) => {
54+
registration.onupdatefound = () => {
55+
const installingWorker = registration.installing;
56+
if (installingWorker) {
57+
installingWorker.onstatechange = () => {
58+
if (installingWorker.state === 'installed') {
59+
if (navigator.serviceWorker.controller) {
60+
// At this point, the old content will have been purged and
61+
// the fresh content will have been added to the cache.
62+
// It's the perfect time to display a 'New content is
63+
// available; please refresh.' message in your web app.
64+
console.log('New content is available; please refresh.');
65+
} else {
66+
// At this point, everything has been precached.
67+
// It's the perfect time to display a
68+
// 'Content is cached for offline use.' message.
69+
console.log('Content is cached for offline use.');
70+
}
71+
}
72+
};
73+
}
74+
};
75+
})
76+
.catch((error) => {
77+
console.error('Error during service worker registration:', error);
78+
});
7979
}
8080

8181
function checkValidServiceWorker(swUrl: string) {
82-
// Check if the service worker can be found. If it can't reload the page.
83-
fetch(swUrl)
84-
.then(response => {
85-
// Ensure service worker exists, and that we really are getting a JS file.
86-
if (
87-
response.status === 404 ||
88-
response.headers.get('content-type')!.indexOf('javascript') === -1
89-
) {
90-
// No service worker found. Probably a different app. Reload the page.
91-
navigator.serviceWorker.ready.then(registration => {
92-
registration.unregister().then(() => {
93-
window.location.reload();
94-
});
82+
// Check if the service worker can be found. If it can't reload the page.
83+
fetch(swUrl)
84+
.then((response) => {
85+
// Ensure service worker exists, and that we really are getting a JS file.
86+
if (
87+
response.status === 404 ||
88+
response.headers.get('content-type')!.indexOf('javascript') === -1
89+
) {
90+
// No service worker found. Probably a different app. Reload the page.
91+
navigator.serviceWorker.ready.then((registration) => {
92+
registration.unregister().then(() => {
93+
window.location.reload();
94+
});
95+
});
96+
} else {
97+
// Service worker found. Proceed as normal.
98+
registerValidSW(swUrl);
99+
}
100+
})
101+
.catch(() => {
102+
console.log(
103+
'No internet connection found. App is running in offline mode.'
104+
);
95105
});
96-
} else {
97-
// Service worker found. Proceed as normal.
98-
registerValidSW(swUrl);
99-
}
100-
})
101-
.catch(() => {
102-
console.log(
103-
'No internet connection found. App is running in offline mode.'
104-
);
105-
});
106106
}
107107

108108
export function unregister() {
109-
if ('serviceWorker' in navigator) {
110-
navigator.serviceWorker.ready.then(registration => {
111-
registration.unregister();
112-
});
113-
}
109+
if ('serviceWorker' in navigator) {
110+
navigator.serviceWorker.ready.then((registration) => {
111+
registration.unregister();
112+
});
113+
}
114114
}

Web/React/react-typescript-toolchain-2018-spring/tsconfig.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@
1919
"strictNullChecks": true,
2020
"suppressImplicitAnyIndexErrors": true,
2121
"noUnusedLocals": true,
22-
"baseUrl": "src"
22+
"baseUrl": "src",
23+
"typeRoots": [
24+
"node_modules/@types",
25+
"typings"
26+
]
2327
},
2428
"exclude": [
2529
"node_modules",
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
declare module '*.svg' {
2+
const content: string;
3+
export default content;
4+
}

0 commit comments

Comments
 (0)