From 9a7075252b087c367c6cf0a47606ffbcc90ad49a Mon Sep 17 00:00:00 2001 From: Niklas von Hertzen Date: Fri, 4 Aug 2017 00:00:02 +0800 Subject: [PATCH] Fix ImageLoader flow types to reflect possible error'd images --- src/ImageLoader.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/ImageLoader.js b/src/ImageLoader.js index 7355623..d7dd706 100644 --- a/src/ImageLoader.js +++ b/src/ImageLoader.js @@ -5,7 +5,7 @@ import type Options from './index'; import type Logger from './Logger'; export type ImageElement = Image | HTMLCanvasElement; -type ImageCache = {[string]: Promise}; +type ImageCache = {[string]: Promise}; export default class ImageLoader { origin: string; @@ -57,11 +57,6 @@ export default class ImageLoader { const img = new Image(); img.onload = () => resolve(img); img.onerror = reject; - /* - if (cors) { - img.crossOrigin = 'anonymous'; - } - */ img.src = src; if (img.complete === true) { resolve(img); @@ -83,11 +78,16 @@ export default class ImageLoader { ready(): Promise { const keys = Object.keys(this.cache); - return Promise.all(keys.map(str => this.cache[str].catch(e => { - if (__DEV__) { - this.logger.log(`Unable to load image`, e); - } - }))).then(images => { + return Promise.all( + keys.map(str => + this.cache[str].catch(e => { + if (__DEV__) { + this.logger.log(`Unable to load image`, e); + } + return null; + }) + ) + ).then(images => { if (__DEV__) { this.logger.log('Finished loading images', images); } @@ -98,9 +98,9 @@ export default class ImageLoader { export class ImageStore { _keys: Array; - _images: Array; + _images: Array; - constructor(keys: Array, images: Array) { + constructor(keys: Array, images: Array) { this._keys = keys; this._images = images; }