Skip to content

Commit

Permalink
Fix ImageLoader flow types to reflect possible error'd images
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasvh committed Aug 3, 2017
1 parent 96fbe95 commit 9a70752
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/ImageLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type Options from './index';
import type Logger from './Logger';

export type ImageElement = Image | HTMLCanvasElement;
type ImageCache = {[string]: Promise<ImageElement>};
type ImageCache = {[string]: Promise<?ImageElement>};

export default class ImageLoader {
origin: string;
Expand Down Expand Up @@ -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);
Expand All @@ -83,11 +78,16 @@ export default class ImageLoader {

ready(): Promise<ImageStore> {
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);
}
Expand All @@ -98,9 +98,9 @@ export default class ImageLoader {

export class ImageStore {
_keys: Array<string>;
_images: Array<ImageElement>;
_images: Array<?ImageElement>;

constructor(keys: Array<string>, images: Array<ImageElement>) {
constructor(keys: Array<string>, images: Array<?ImageElement>) {
this._keys = keys;
this._images = images;
}
Expand Down

0 comments on commit 9a70752

Please sign in to comment.