Created
May 26, 2015 15:21
-
-
Save chrism/c35756037f5feaac5023 to your computer and use it in GitHub Desktop.
Preloading images using Ember.JS util
This file contains hidden or 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
import Ember from 'ember'; | |
var Promise = Ember.RSVP.Promise; | |
export default function preloadImages(...urls) { | |
let promises = urls.map(url => { | |
return new Promise((resolve, reject) => { | |
let image = new Image(); | |
image.onload = resolve; | |
image.onerror = reject; | |
image.src = url; | |
}); | |
}); | |
return Promise.all(promises); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for sharing, I added this to my app and works great :)