Async or parallel, single image or multi image loader with progress using native Promises.
ILoader is a very lightweight object to help with parallel and sequential image loading in an application. ILoader has no UI - it simply returns the consumer a progress/complete via callback/Promise based on the image queue that is passed in.
npm install i-loader --save-dev
import ILoader from 'i-loader';
const imageLoader = new ILoader({
onProgress(progress){
console.log(`progress on the queue ${progress}`);
}
});
/*
* Call load and pass in an array of images
* load() returns a promise
*/
imageLoader.load([
'image-1.jpg',
'image-2.jpg',
'image-3.jpg',
'image-4.jpg'
]).then(() => {
console.log('Queue is complete!');
});
const imageLoader = new ILoader({
onProgress(progress){
console.log(`progress on the queue ${progress}`);
}
});
/*
* Call load and pass in a string
*/
imageLoader.load(
'image-2.jpg'
).then(() => {
console.log('Queue is complete!');
});
There are a couple of options you can pass in to the constructor
async
- Default isfalse
- Passtrue
to have images load in sequential orderonProgress
- Default isnull
- Function that returns progress, from 0-100
npm test