Improve code style of examples.

Consts are preferable because readers don't have to think about potential
future code paths affecting the value.
This commit is contained in:
Dylan Vann 2017-06-20 00:53:32 -04:00
parent d2e13b958e
commit c21c24c4de
1 changed files with 25 additions and 20 deletions

View File

@ -8,24 +8,29 @@ import uuid from 'uuid/v4'
const getImageUrl = (id, width, height) =>
`https://source.unsplash.com/${id}/${width}x${height}`
let IMAGE_1
let IMAGE_2
let IMAGE_3
const IMAGE_SIZE = 150
const USE_SERVER = false
const token = 'someToken'
if (USE_SERVER) {
const TOKEN = 'someToken'
const getImages = () => {
if (USE_SERVER) {
const baseUrl = '192.168.2.11'
IMAGE_1 = `http://${baseUrl}:8080/pictures/ahmed-saffu-235616.jpg`
IMAGE_2 = `http://${baseUrl}:8080/pictures/alex-bertha-236361.jpg`
IMAGE_3 = `http://${baseUrl}:8080/pictures/jaromir-kavan-233699.jpg`
} else {
IMAGE_1 = getImageUrl('x58soEovG_M', IMAGE_SIZE, IMAGE_SIZE)
IMAGE_2 = getImageUrl('yPI7myL5eWY', IMAGE_SIZE, IMAGE_SIZE)
IMAGE_3 =
'https://cdn-images-1.medium.com/max/1600/1*-CY5bU4OqiJRox7G00sftw.gif'
return [
`http://${baseUrl}:8080/pictures/ahmed-saffu-235616.jpg`,
`http://${baseUrl}:8080/pictures/alex-bertha-236361.jpg`,
`http://${baseUrl}:8080/pictures/jaromir-kavan-233699.jpg`,
]
}
return [
getImageUrl('x58soEovG_M', IMAGE_SIZE, IMAGE_SIZE),
getImageUrl('yPI7myL5eWY', IMAGE_SIZE, IMAGE_SIZE),
'https://cdn-images-1.medium.com/max/1600/1*-CY5bU4OqiJRox7G00sftw.gif',
]
}
const images = getImages()
class FastImageExample extends Component {
componentDidMount() {
// Forcing an update every 5s to demonstrate loading.
@ -58,9 +63,9 @@ class FastImageExample extends Component {
<FastImage
style={styles.image}
source={{
uri: IMAGE_1 + bust,
uri: images[0] + bust,
headers: {
token,
token: TOKEN,
},
priority: FastImage.priority.low,
}}
@ -68,9 +73,9 @@ class FastImageExample extends Component {
<FastImage
style={styles.image}
source={{
uri: IMAGE_2 + bust,
uri: images[1] + bust,
headers: {
token,
token: TOKEN,
},
priority: FastImage.priority.normal,
}}
@ -78,9 +83,9 @@ class FastImageExample extends Component {
<FastImage
style={styles.image}
source={{
uri: IMAGE_3 + bust,
uri: images[2] + bust,
headers: {
token,
token: TOKEN,
},
priority: FastImage.priority.high,
}}