Enhance load image performance

This commit is contained in:
Qolzam
2017-08-24 21:52:34 +07:00
parent 013a8d5c2e
commit bca0752535
9 changed files with 178 additions and 186 deletions

View File

@@ -43,7 +43,6 @@ export class Img extends Component {
}
// Binding functions to `this`
this.getImageURL = this.getImageURL.bind(this)
this.handleLoadImage = this.handleLoadImage.bind(this)
}
@@ -59,29 +58,6 @@ export class Img extends Component {
})
}
/**
* Get image url if it is not exist on redux store
*
* @memberof Img
*/
getImageURL = () => {
let { fileName } = this.props
if (fileName && fileName !== '') {
if (this.props.imageRequests.indexOf(fileName) > -1)
return
this.props.getImage(fileName)
}
}
componentWillMount() {
let { fileName } = this.props
if (this.props.imageRequests.indexOf(fileName) > -1)
return
this.getImageURL()
}
/**
* Reneder component DOM
* @return {react element} return the DOM which rendered by component
@@ -114,7 +90,7 @@ export class Img extends Component {
let { isImageLoaded } = this.state
return (
<div>
<img onLoad={this.handleLoadImage} src={this.props.avatarURL[fileName] || ''} style={isImageLoaded ? style : { display: 'none' }} />
<img onLoad={this.handleLoadImage} src={fileName || ''} style={isImageLoaded ? style : { display: 'none' }} />
<div style={{ backgroundColor: 'blue' }} style={isImageLoaded ? { display: 'none' } : styles.loding}>
<div style={styles.loadingContent}>
<SvgImage style={styles.loadingImage} />
@@ -136,8 +112,7 @@ export class Img extends Component {
*/
const mapDispatchToProps = (dispatch, ownProps) => {
return {
getImage: (name) => dispatch(imageGalleryActions.dbDownloadImage(name))
}
}