Created
July 1, 2017 22:51
-
-
Save conanak99/204b144526089201a4e0d28a093826ca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
loadMoreImageIntoStore: async function() { | |
let newImages = await this.fetchImageFromAPI(); | |
newImages.normal.forEach(imageUrl => { | |
if (this.imageStore.normal.indexOf(imageUrl) === -1) { | |
this.imageStore.normal.push(imageUrl); | |
preloadImage(imageUrl); | |
} | |
}); | |
newImages.sexy.forEach(imageUrl => { | |
if (this.imageStore.sexy.indexOf(imageUrl) === -1) { | |
this.imageStore.sexy.push(imageUrl); | |
preloadImage(imageUrl); | |
} | |
}); | |
StorageService.setImageStore(this.imageStore); | |
}, | |
getRewardImage: function(score) { | |
var imageUrl = ''; | |
// Lấy ảnh từ local storage, trả ra cho người dùng | |
if (score % 4 === 0) { | |
imageUrl = this.imageStore.sexy.shift(); | |
} else { | |
imageUrl = this.imageStore.normal.shift(); | |
} | |
StorageService.setImageStore(this.imageStore); | |
// Tải thêm hình từ API | |
// Chạy ngầm để không ảnh hưởng tới UI/UX | |
if (this.imageStore.normal.length < 6) { | |
this.loadMoreImageIntoStore(); | |
} | |
return imageUrl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment