LyonDataViz / occupapp

Occupapp
https://occupapp.now.sh/
GNU General Public License v3.0
3 stars 2 forks source link

Promise to wait for an image to have loaded #63

Open severo opened 4 years ago

severo commented 4 years ago

We could use https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/decode#Examples instead of https://github.com/LyonDataViz/occupapp/blob/07624ea038016dc67d56021811f17e7fb4227707/src/utils/img.ts#L5...

severo commented 4 years ago
fetchImage = src => {
  const img = new Image();
  img.src = src;
  return img
    .decode()
    .then(() => img)
    .catch(encodingError => {
      // Do something with the error.
      throw new Error(`Image ${src} could not be loaded: ${encodingError}`);
    });
}