Skip to content

Instantly share code, notes, and snippets.

@zurie
Created June 10, 2017 00:05
Show Gist options
  • Save zurie/5cfcc96f1afb1ecdf50c60abe394338d to your computer and use it in GitHub Desktop.
Save zurie/5cfcc96f1afb1ecdf50c60abe394338d to your computer and use it in GitHub Desktop.
export function imgResolver(resourceProvider: ResourceProvider) {
const preloadImgs: string[] = ['/assets/bg_color.jpg', '/assets/bg_bw.jpg'];
return new Promise(function (resolve) {
const preloadImage = (img: HTMLImageElement) => console.log(img.src + ' loaded!');
const preloadError = (err: Error) => console.log('Preload Error!' + err);
const preloadComplete = () => setTimeout(resolve, 0);
return resourceProvider.preloadImages(preloadImgs)
.subscribe((img: HTMLImageElement) => preloadImage(img), (err: Error) => preloadError(err), () => preloadComplete());
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment