Skip to content

Commit

Permalink
feat: turning renderers to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
WoodNeck committed Nov 9, 2020
1 parent 25ad54f commit f7ab6a9
Show file tree
Hide file tree
Showing 14 changed files with 227 additions and 1,026 deletions.
30 changes: 17 additions & 13 deletions src/PanoImageRenderer/ImageLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,11 @@ class ImageLoader extends Component<{
return images.length === 1 ? images[0] : images;
}

public onceLoaded(target: HTMLImageElement | HTMLImageElement[], onload, onerror) {
public onceLoaded(
target: HTMLImageElement | HTMLImageElement[],
onload: (images: HTMLImageElement | HTMLImageElement[]) => any,
onerror: (images: HTMLImageElement | HTMLImageElement[]) => any
) {
const targets = target instanceof Array ? target : [target];
const targetsNotLoaded = targets.filter(img => !ImageLoader.isMaybeLoaded(img));
const loadPromises = targetsNotLoaded.map(img => new Promise((res, rej) => {
Expand All @@ -150,21 +154,11 @@ class ImageLoader extends Component<{
);
}

_once(target, type, listener) {
const fn = event => {
target.removeEventListener(type, fn);
listener(event);
};

target.addEventListener(type, fn);
this._onceHandlers.push({target, type, fn});
}

getStatus() {
public getStatus() {
return this._loadStatus;
}

destroy() {
public destroy() {
this._onceHandlers.forEach(handler => {
handler.target.removeEventListener(handler.type, handler.fn);
});
Expand All @@ -173,6 +167,16 @@ class ImageLoader extends Component<{
this._image = null;
this._loadStatus = STATUS.NONE;
}

private _once(target: HTMLImageElement, type: string, listener: (evt: Event) => any) {
const fn = event => {
target.removeEventListener(type, fn);
listener(event);
};

target.addEventListener(type, fn);
this._onceHandlers.push({target, type, fn});
}
}

export default ImageLoader;
Loading

0 comments on commit f7ab6a9

Please sign in to comment.