Skip to content

Commit c21c24c

Browse files
committed
Improve code style of examples.
Consts are preferable because readers don't have to think about potential future code paths affecting the value.
1 parent d2e13b9 commit c21c24c

File tree

1 file changed

+25
-20
lines changed

1 file changed

+25
-20
lines changed

example/FastImageExample.js

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,29 @@ import uuid from 'uuid/v4'
88

99
const getImageUrl = (id, width, height) =>
1010
`https://source.unsplash.com/${id}/${width}x${height}`
11-
let IMAGE_1
12-
let IMAGE_2
13-
let IMAGE_3
11+
1412
const IMAGE_SIZE = 150
1513
const USE_SERVER = false
16-
const token = 'someToken'
17-
if (USE_SERVER) {
18-
const baseUrl = '192.168.2.11'
19-
IMAGE_1 = `http://${baseUrl}:8080/pictures/ahmed-saffu-235616.jpg`
20-
IMAGE_2 = `http://${baseUrl}:8080/pictures/alex-bertha-236361.jpg`
21-
IMAGE_3 = `http://${baseUrl}:8080/pictures/jaromir-kavan-233699.jpg`
22-
} else {
23-
IMAGE_1 = getImageUrl('x58soEovG_M', IMAGE_SIZE, IMAGE_SIZE)
24-
IMAGE_2 = getImageUrl('yPI7myL5eWY', IMAGE_SIZE, IMAGE_SIZE)
25-
IMAGE_3 =
26-
'https://cdn-images-1.medium.com/max/1600/1*-CY5bU4OqiJRox7G00sftw.gif'
14+
const TOKEN = 'someToken'
15+
16+
const getImages = () => {
17+
if (USE_SERVER) {
18+
const baseUrl = '192.168.2.11'
19+
return [
20+
`http://${baseUrl}:8080/pictures/ahmed-saffu-235616.jpg`,
21+
`http://${baseUrl}:8080/pictures/alex-bertha-236361.jpg`,
22+
`http://${baseUrl}:8080/pictures/jaromir-kavan-233699.jpg`,
23+
]
24+
}
25+
return [
26+
getImageUrl('x58soEovG_M', IMAGE_SIZE, IMAGE_SIZE),
27+
getImageUrl('yPI7myL5eWY', IMAGE_SIZE, IMAGE_SIZE),
28+
'https://cdn-images-1.medium.com/max/1600/1*-CY5bU4OqiJRox7G00sftw.gif',
29+
]
2730
}
2831

32+
const images = getImages()
33+
2934
class FastImageExample extends Component {
3035
componentDidMount() {
3136
// Forcing an update every 5s to demonstrate loading.
@@ -58,29 +63,29 @@ class FastImageExample extends Component {
5863
<FastImage
5964
style={styles.image}
6065
source={{
61-
uri: IMAGE_1 + bust,
66+
uri: images[0] + bust,
6267
headers: {
63-
token,
68+
token: TOKEN,
6469
},
6570
priority: FastImage.priority.low,
6671
}}
6772
/>
6873
<FastImage
6974
style={styles.image}
7075
source={{
71-
uri: IMAGE_2 + bust,
76+
uri: images[1] + bust,
7277
headers: {
73-
token,
78+
token: TOKEN,
7479
},
7580
priority: FastImage.priority.normal,
7681
}}
7782
/>
7883
<FastImage
7984
style={styles.image}
8085
source={{
81-
uri: IMAGE_3 + bust,
86+
uri: images[2] + bust,
8287
headers: {
83-
token,
88+
token: TOKEN,
8489
},
8590
priority: FastImage.priority.high,
8691
}}

0 commit comments

Comments
 (0)