Skip to content

Commit 7a9d860

Browse files
nissy-devfacebook-github-bot
authored andcommitted
Remove var in RNTester (#22017)
Summary: I removed `var` in RNTester. - [x] npm run prettier - [x] npm run flow-check-ios - [x] npm run flow-check-android [GENERAL] [ENHANCEMENT] [RNTester] - remove `var` Pull Request resolved: #22017 Differential Revision: D12843109 Pulled By: TheSavior fbshipit-source-id: 936ed5efdcff2e7b85e90ed90c589eb98c60c411
1 parent a06c0da commit 7a9d860

15 files changed

+102
-101
lines changed

Diff for: RNTester/js/LayoutEventsExample.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
'use strict';
1212

13-
var React = require('react');
14-
var ReactNative = require('react-native');
15-
var {Image, LayoutAnimation, StyleSheet, Text, View} = ReactNative;
13+
const React = require('react');
14+
const ReactNative = require('react-native');
15+
const {Image, LayoutAnimation, StyleSheet, Text, View} = ReactNative;
1616

1717
import type {ViewLayout, ViewLayoutEvent} from 'ViewPropTypes';
1818

@@ -71,9 +71,9 @@ class LayoutEventExample extends React.Component<{}, State> {
7171
};
7272

7373
render() {
74-
var viewStyle = [styles.view, this.state.viewStyle];
75-
var textLayout = this.state.textLayout || {width: '?', height: '?'};
76-
var imageLayout = this.state.imageLayout || {x: '?', y: '?'};
74+
const viewStyle = [styles.view, this.state.viewStyle];
75+
const textLayout = this.state.textLayout || {width: '?', height: '?'};
76+
const imageLayout = this.state.imageLayout || {x: '?', y: '?'};
7777
return (
7878
<View style={this.state.containerStyle}>
7979
<Text>
@@ -113,7 +113,7 @@ class LayoutEventExample extends React.Component<{}, State> {
113113
}
114114
}
115115

116-
var styles = StyleSheet.create({
116+
const styles = StyleSheet.create({
117117
view: {
118118
padding: 12,
119119
borderColor: 'black',

Diff for: RNTester/js/LayoutExample.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010

1111
'use strict';
1212

13-
var React = require('react');
14-
var ReactNative = require('react-native');
15-
var {StyleSheet, Text, View} = ReactNative;
13+
const React = require('react');
14+
const ReactNative = require('react-native');
15+
const {StyleSheet, Text, View} = ReactNative;
1616

17-
var RNTesterBlock = require('./RNTesterBlock');
18-
var RNTesterPage = require('./RNTesterPage');
17+
const RNTesterBlock = require('./RNTesterBlock');
18+
const RNTesterPage = require('./RNTesterPage');
1919

2020
class Circle extends React.Component<$FlowFixMeProps> {
2121
render() {
22-
var size = this.props.size || 20;
23-
var backgroundColor = this.props.bgColor || '#527fe4';
22+
const size = this.props.size || 20;
23+
const backgroundColor = this.props.bgColor || '#527fe4';
2424
return (
2525
<View
2626
style={{
@@ -37,7 +37,7 @@ class Circle extends React.Component<$FlowFixMeProps> {
3737

3838
class CircleBlock extends React.Component<$FlowFixMeProps> {
3939
render() {
40-
var circleStyle = {
40+
const circleStyle = {
4141
flexDirection: 'row',
4242
backgroundColor: '#f6f7f8',
4343
borderWidth: 0.5,
@@ -56,7 +56,7 @@ class LayoutExample extends React.Component<$FlowFixMeProps> {
5656
static displayName = 'LayoutExample';
5757

5858
render() {
59-
var fiveColoredCircles = [
59+
const fiveColoredCircles = [
6060
<Circle bgColor="#527fe4" key="blue" />,
6161
<Circle bgColor="#D443E3" key="violet" />,
6262
<Circle bgColor="#FF9049" key="orange" />,
@@ -186,7 +186,7 @@ class LayoutExample extends React.Component<$FlowFixMeProps> {
186186
}
187187
}
188188

189-
var styles = StyleSheet.create({
189+
const styles = StyleSheet.create({
190190
overlay: {
191191
backgroundColor: '#aaccff',
192192
borderRadius: 10,

Diff for: RNTester/js/ListViewExample.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ class ListViewSimpleExample extends React.Component<RNTesterProps, State> {
6969
rowID: number,
7070
highlightRow: (sectionID: number, rowID: number) => void,
7171
) => {
72-
var rowHash = Math.abs(hashCode(rowData));
73-
var imgSource = THUMB_URLS[rowHash % THUMB_URLS.length];
72+
const rowHash = Math.abs(hashCode(rowData));
73+
const imgSource = THUMB_URLS[rowHash % THUMB_URLS.length];
7474
return (
7575
<TouchableHighlight
7676
onPress={() => {
@@ -90,9 +90,9 @@ class ListViewSimpleExample extends React.Component<RNTesterProps, State> {
9090
};
9191

9292
_genRows(pressData: {[key: number]: boolean}): Array<string> {
93-
var dataBlob = [];
94-
for (var ii = 0; ii < 100; ii++) {
95-
var pressedText = pressData[ii] ? ' (pressed)' : '';
93+
const dataBlob = [];
94+
for (let ii = 0; ii < 100; ii++) {
95+
const pressedText = pressData[ii] ? ' (pressed)' : '';
9696
dataBlob.push('Row ' + ii + pressedText);
9797
}
9898
return dataBlob;
@@ -124,7 +124,7 @@ class ListViewSimpleExample extends React.Component<RNTesterProps, State> {
124124
}
125125
}
126126

127-
var THUMB_URLS = [
127+
const THUMB_URLS = [
128128
require('./Thumbnails/like.png'),
129129
require('./Thumbnails/dislike.png'),
130130
require('./Thumbnails/call.png'),
@@ -138,19 +138,19 @@ var THUMB_URLS = [
138138
require('./Thumbnails/superlike.png'),
139139
require('./Thumbnails/victory.png'),
140140
];
141-
var LOREM_IPSUM =
141+
const LOREM_IPSUM =
142142
'Lorem ipsum dolor sit amet, ius ad pertinax oportere accommodare, an vix civibus corrumpit referrentur. Te nam case ludus inciderint, te mea facilisi adipiscing. Sea id integre luptatum. In tota sale consequuntur nec. Erat ocurreret mei ei. Eu paulo sapientem vulputate est, vel an accusam intellegam interesset. Nam eu stet pericula reprimique, ea vim illud modus, putant invidunt reprehendunt ne qui.';
143143

144144
/* eslint no-bitwise: 0 */
145-
var hashCode = function(str) {
146-
var hash = 15;
147-
for (var ii = str.length - 1; ii >= 0; ii--) {
145+
const hashCode = function(str) {
146+
let hash = 15;
147+
for (let ii = str.length - 1; ii >= 0; ii--) {
148148
hash = (hash << 5) - hash + str.charCodeAt(ii);
149149
}
150150
return hash;
151151
};
152152

153-
var styles = StyleSheet.create({
153+
const styles = StyleSheet.create({
154154
row: {
155155
flexDirection: 'row',
156156
justifyContent: 'center',

Diff for: RNTester/js/ListViewGridLayoutExample.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const ListViewDataSource = require('ListViewDataSource');
2424

2525
import type {RNTesterProps} from 'RNTesterTypes';
2626

27-
var THUMB_URLS = [
27+
const THUMB_URLS = [
2828
require('./Thumbnails/like.png'),
2929
require('./Thumbnails/dislike.png'),
3030
require('./Thumbnails/call.png'),
@@ -78,8 +78,8 @@ class ListViewGridLayoutExample extends React.Component<RNTesterProps, State> {
7878
}
7979

8080
_renderRow = (rowData: string, sectionID: number, rowID: number) => {
81-
var rowHash = Math.abs(hashCode(rowData));
82-
var imgSource = THUMB_URLS[rowHash % THUMB_URLS.length];
81+
const rowHash = Math.abs(hashCode(rowData));
82+
const imgSource = THUMB_URLS[rowHash % THUMB_URLS.length];
8383
return (
8484
<TouchableHighlight
8585
onPress={() => this._pressRow(rowID)}
@@ -95,9 +95,9 @@ class ListViewGridLayoutExample extends React.Component<RNTesterProps, State> {
9595
};
9696

9797
_genRows(pressData: {[key: number]: boolean}): Array<string> {
98-
var dataBlob = [];
99-
for (var ii = 0; ii < 100; ii++) {
100-
var pressedText = pressData[ii] ? ' (X)' : '';
98+
const dataBlob = [];
99+
for (let ii = 0; ii < 100; ii++) {
100+
const pressedText = pressData[ii] ? ' (X)' : '';
101101
dataBlob.push('Cell ' + ii + pressedText);
102102
}
103103
return dataBlob;
@@ -114,15 +114,15 @@ class ListViewGridLayoutExample extends React.Component<RNTesterProps, State> {
114114
}
115115

116116
/* eslint no-bitwise: 0 */
117-
var hashCode = function(str) {
118-
var hash = 15;
119-
for (var ii = str.length - 1; ii >= 0; ii--) {
117+
const hashCode = function(str) {
118+
let hash = 15;
119+
for (let ii = str.length - 1; ii >= 0; ii--) {
120120
hash = (hash << 5) - hash + str.charCodeAt(ii);
121121
}
122122
return hash;
123123
};
124124

125-
var styles = StyleSheet.create({
125+
const styles = StyleSheet.create({
126126
list: {
127127
justifyContent: 'space-around',
128128
flexDirection: 'row',

Diff for: RNTester/js/ListViewPagingExample.js

+24-24
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
'use strict';
1212

13-
var React = require('react');
14-
var ReactNative = require('react-native');
15-
var {
13+
const React = require('react');
14+
const ReactNative = require('react-native');
15+
const {
1616
Image,
1717
LayoutAnimation,
1818
ListView,
@@ -22,10 +22,10 @@ var {
2222
View,
2323
} = ReactNative;
2424

25-
var NativeModules = require('NativeModules');
26-
var {UIManager} = NativeModules;
25+
const NativeModules = require('NativeModules');
26+
const {UIManager} = NativeModules;
2727

28-
var THUMB_URLS = [
28+
const THUMB_URLS = [
2929
require('./Thumbnails/like.png'),
3030
require('./Thumbnails/dislike.png'),
3131
require('./Thumbnails/call.png'),
@@ -39,8 +39,8 @@ var THUMB_URLS = [
3939
require('./Thumbnails/superlike.png'),
4040
require('./Thumbnails/victory.png'),
4141
];
42-
var NUM_SECTIONS = 100;
43-
var NUM_ROWS_PER_SECTION = 10;
42+
const NUM_SECTIONS = 100;
43+
const NUM_ROWS_PER_SECTION = 10;
4444

4545
class Thumb extends React.Component<{}, $FlowFixMeState> {
4646
UNSAFE_componentWillMount() {
@@ -53,7 +53,7 @@ class Thumb extends React.Component<{}, $FlowFixMeState> {
5353
};
5454

5555
_onPressThumb = () => {
56-
var config =
56+
const config =
5757
layoutAnimationConfigs[
5858
this.state.thumbIndex % layoutAnimationConfigs.length
5959
];
@@ -94,31 +94,31 @@ class ListViewPagingExample extends React.Component<$FlowFixMeProps, *> {
9494
// $FlowFixMe found when converting React.createClass to ES6
9595
constructor(props) {
9696
super(props);
97-
var getSectionData = (dataBlob, sectionID) => {
97+
const getSectionData = (dataBlob, sectionID) => {
9898
return dataBlob[sectionID];
9999
};
100-
var getRowData = (dataBlob, sectionID, rowID) => {
100+
const getRowData = (dataBlob, sectionID, rowID) => {
101101
return dataBlob[rowID];
102102
};
103103

104-
var dataSource = new ListView.DataSource({
104+
const dataSource = new ListView.DataSource({
105105
getRowData: getRowData,
106106
getSectionHeaderData: getSectionData,
107107
rowHasChanged: (row1, row2) => row1 !== row2,
108108
sectionHeaderHasChanged: (s1, s2) => s1 !== s2,
109109
});
110110

111-
var dataBlob = {};
112-
var sectionIDs = [];
113-
var rowIDs = [];
114-
for (var ii = 0; ii < NUM_SECTIONS; ii++) {
115-
var sectionName = 'Section ' + ii;
111+
const dataBlob = {};
112+
const sectionIDs = [];
113+
const rowIDs = [];
114+
for (let ii = 0; ii < NUM_SECTIONS; ii++) {
115+
const sectionName = 'Section ' + ii;
116116
sectionIDs.push(sectionName);
117117
dataBlob[sectionName] = sectionName;
118118
rowIDs[ii] = [];
119119

120-
for (var jj = 0; jj < NUM_ROWS_PER_SECTION; jj++) {
121-
var rowName = 'S' + ii + ', R' + jj;
120+
for (let jj = 0; jj < NUM_ROWS_PER_SECTION; jj++) {
121+
const rowName = 'S' + ii + ', R' + jj;
122122
rowIDs[ii].push(rowName);
123123
dataBlob[rowName] = rowName;
124124
}
@@ -151,7 +151,7 @@ class ListViewPagingExample extends React.Component<$FlowFixMeProps, *> {
151151
};
152152

153153
renderHeader = () => {
154-
var headerLikeText =
154+
const headerLikeText =
155155
this.state.headerPressCount % 2 ? (
156156
<View>
157157
<Text style={styles.text}>1 Like</Text>
@@ -198,7 +198,7 @@ class ListViewPagingExample extends React.Component<$FlowFixMeProps, *> {
198198
}
199199

200200
_onPressHeader = () => {
201-
var config =
201+
const config =
202202
layoutAnimationConfigs[
203203
Math.floor(this.state.headerPressCount / 2) %
204204
layoutAnimationConfigs.length
@@ -208,7 +208,7 @@ class ListViewPagingExample extends React.Component<$FlowFixMeProps, *> {
208208
};
209209
}
210210

211-
var styles = StyleSheet.create({
211+
const styles = StyleSheet.create({
212212
listview: {
213213
backgroundColor: '#B0C4DE',
214214
},
@@ -256,7 +256,7 @@ var styles = StyleSheet.create({
256256
},
257257
});
258258

259-
var animations = {
259+
const animations = {
260260
layout: {
261261
spring: {
262262
duration: 750,
@@ -284,7 +284,7 @@ var animations = {
284284
},
285285
};
286286

287-
var layoutAnimationConfigs = [
287+
const layoutAnimationConfigs = [
288288
animations.layout.spring,
289289
animations.layout.easeInEaseOut,
290290
];

Diff for: RNTester/js/ModalExample.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
'use strict';
1212

13-
var React = require('react');
14-
var ReactNative = require('react-native');
15-
var {
13+
const React = require('react');
14+
const ReactNative = require('react-native');
15+
const {
1616
Modal,
1717
Picker,
1818
Platform,
@@ -44,7 +44,7 @@ class Button extends React.Component<$FlowFixMeProps, $FlowFixMeState> {
4444
};
4545

4646
render() {
47-
var colorStyle = {
47+
const colorStyle = {
4848
color: this.state.active ? '#fff' : '#000',
4949
};
5050
return (
@@ -106,15 +106,15 @@ class ModalExample extends React.Component<{}, $FlowFixMeState> {
106106
}
107107

108108
render() {
109-
var modalBackgroundStyle = {
109+
const modalBackgroundStyle = {
110110
backgroundColor: this.state.transparent
111111
? 'rgba(0, 0, 0, 0.5)'
112112
: '#f5fcff',
113113
};
114-
var innerContainerTransparentStyle = this.state.transparent
114+
const innerContainerTransparentStyle = this.state.transparent
115115
? {backgroundColor: '#fff', padding: 20}
116116
: null;
117-
var activeButtonStyle = {
117+
const activeButtonStyle = {
118118
backgroundColor: '#ddd',
119119
};
120120

@@ -241,7 +241,7 @@ exports.examples = [
241241
},
242242
];
243243

244-
var styles = StyleSheet.create({
244+
const styles = StyleSheet.create({
245245
container: {
246246
flex: 1,
247247
justifyContent: 'center',

Diff for: RNTester/js/NativeAnimationsExample.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const {
2121
Slider,
2222
} = ReactNative;
2323

24-
var AnimatedSlider = Animated.createAnimatedComponent(Slider);
24+
const AnimatedSlider = Animated.createAnimatedComponent(Slider);
2525

2626
class Tester extends React.Component<$FlowFixMeProps, $FlowFixMeState> {
2727
state = {

Diff for: RNTester/js/PanResponderExample.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class PanResponderExample extends React.Component<Props> {
126126
}
127127
}
128128

129-
var styles = StyleSheet.create({
129+
const styles = StyleSheet.create({
130130
circle: {
131131
width: CIRCLE_SIZE,
132132
height: CIRCLE_SIZE,

0 commit comments

Comments
 (0)