Created
February 7, 2017 17:36
-
-
Save iddan/fbee78cbc988342efe7e653b0d82b017 to your computer and use it in GitHub Desktop.
One liner to load images with a promise
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
const loadImage = src => new Promise((resolve, reject) => Object.assign(new Image(), { | |
src, | |
onload() { | |
resolve(this); | |
}, | |
onerror(err) { | |
reject(err); | |
}, | |
})); | |
export default loadImage; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment