mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
Fix ImageLoader flow types to reflect possible error'd images
This commit is contained in:
parent
96fbe954e9
commit
9a7075252b
@ -5,7 +5,7 @@ import type Options from './index';
|
|||||||
import type Logger from './Logger';
|
import type Logger from './Logger';
|
||||||
|
|
||||||
export type ImageElement = Image | HTMLCanvasElement;
|
export type ImageElement = Image | HTMLCanvasElement;
|
||||||
type ImageCache = {[string]: Promise<ImageElement>};
|
type ImageCache = {[string]: Promise<?ImageElement>};
|
||||||
|
|
||||||
export default class ImageLoader {
|
export default class ImageLoader {
|
||||||
origin: string;
|
origin: string;
|
||||||
@ -57,11 +57,6 @@ export default class ImageLoader {
|
|||||||
const img = new Image();
|
const img = new Image();
|
||||||
img.onload = () => resolve(img);
|
img.onload = () => resolve(img);
|
||||||
img.onerror = reject;
|
img.onerror = reject;
|
||||||
/*
|
|
||||||
if (cors) {
|
|
||||||
img.crossOrigin = 'anonymous';
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
img.src = src;
|
img.src = src;
|
||||||
if (img.complete === true) {
|
if (img.complete === true) {
|
||||||
resolve(img);
|
resolve(img);
|
||||||
@ -83,11 +78,16 @@ export default class ImageLoader {
|
|||||||
|
|
||||||
ready(): Promise<ImageStore> {
|
ready(): Promise<ImageStore> {
|
||||||
const keys = Object.keys(this.cache);
|
const keys = Object.keys(this.cache);
|
||||||
return Promise.all(keys.map(str => this.cache[str].catch(e => {
|
return Promise.all(
|
||||||
if (__DEV__) {
|
keys.map(str =>
|
||||||
this.logger.log(`Unable to load image`, e);
|
this.cache[str].catch(e => {
|
||||||
}
|
if (__DEV__) {
|
||||||
}))).then(images => {
|
this.logger.log(`Unable to load image`, e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
})
|
||||||
|
)
|
||||||
|
).then(images => {
|
||||||
if (__DEV__) {
|
if (__DEV__) {
|
||||||
this.logger.log('Finished loading images', images);
|
this.logger.log('Finished loading images', images);
|
||||||
}
|
}
|
||||||
@ -98,9 +98,9 @@ export default class ImageLoader {
|
|||||||
|
|
||||||
export class ImageStore {
|
export class ImageStore {
|
||||||
_keys: Array<string>;
|
_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._keys = keys;
|
||||||
this._images = images;
|
this._images = images;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user