Skip to content

Instantly share code, notes, and snippets.

@conanak99
Created July 1, 2017 22:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save conanak99/204b144526089201a4e0d28a093826ca to your computer and use it in GitHub Desktop.
Save conanak99/204b144526089201a4e0d28a093826ca to your computer and use it in GitHub Desktop.
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