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