Socket
Socket
Sign inDemoInstall

resource-loader

Package Overview
Dependencies
2
Maintainers
1
Versions
57
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.3.1 to 1.3.2

2

package.json
{
"name": "resource-loader",
"version": "1.3.1",
"version": "1.3.2",
"main": "./src/index.js",

@@ -5,0 +5,0 @@ "description": "A generic asset loader, made with web games in mind.",

@@ -68,10 +68,2 @@ var async = require('async'),

/**
* The `_onComplete` function bound with this object context.
*
* @private
* @member {function}
*/
this._boundOnComplete = this._onComplete.bind(this);
/**
* The `_onLoad` function bound with this object context.

@@ -93,7 +85,16 @@ *

/**
* Used to track load completion.
*
* @private
* @member {number}
*/
this._numToLoad = 0;
/**
* The resources waiting to be loaded.
*
* @private
* @member {Resource[]}
*/
this.queue = async.queue(this._boundLoadResource, concurrency);
this._queue = async.queue(this._boundLoadResource, concurrency);

@@ -111,2 +112,3 @@ /**

* @event progress
* @memberof Loader#
*/

@@ -118,2 +120,3 @@

* @event error
* @memberof Loader#
*/

@@ -125,2 +128,3 @@

* @event load
* @memberof Loader#
*/

@@ -132,2 +136,3 @@

* @event start
* @memberof Loader#
*/

@@ -139,2 +144,3 @@

* @event complete
* @memberof Loader#
*/

@@ -251,6 +257,8 @@ }

this._numToLoad++;
// if already loading add it to the worker queue
if (this.queue.started) {
this.queue.push(this.resources[name]);
this._progressChunk = (100 - this.progress) / (this.queue.length() + this.queue.running());
if (this._queue.started) {
this._queue.push(this.resources[name]);
this._progressChunk = (100 - this.progress) / (this._queue.length() + this._queue.running());
}

@@ -303,4 +311,4 @@ // otherwise buffer it to be added to the queue later

this.queue.kill();
this.queue.started = false;
this._queue.kill();
this._queue.started = false;

@@ -326,9 +334,6 @@ this.progress = 0;

// if the queue has already started we are done here
if (this.queue.started) {
if (this._queue.started) {
return this;
}
// set drain event callback
this.queue.drain = this._boundOnComplete;
// notify of start

@@ -339,3 +344,3 @@ this.emit('start', this);

for (var i = 0; i < this._buffer.length; ++i) {
this.queue.push(this._buffer[i]);
this._queue.push(this._buffer[i]);
}

@@ -400,2 +405,9 @@

resource.emit('afterMiddleware', resource);
this._numToLoad--;
// do completion check
if (this._numToLoad === 0) {
this._onComplete();
}
});

@@ -402,0 +414,0 @@

@@ -62,3 +62,3 @@ var EventEmitter = require('eventemitter3').EventEmitter,

*/
this.loadType = options.loadType || Resource.LOAD_TYPE.XHR;
this.loadType = options.loadType || this._determineLoadType();

@@ -131,2 +131,3 @@ /**

* @event start
* @memberof Resource#
*/

@@ -142,2 +143,3 @@

* @event progress
* @memberof Resource#
*/

@@ -150,2 +152,3 @@

* @event complete
* @memberof Resource#
*/

@@ -528,2 +531,3 @@ }

case 'png':
case 'bmp':
case 'jpg':

@@ -549,2 +553,22 @@ case 'jpeg':

Resource.prototype._determineLoadType = function () {
var ext = this.url.substr(this.url.lastIndexOf('.') + 1);
switch(ext) {
// images
case 'gif':
case 'png':
case 'bmp':
case 'jpg':
case 'jpeg':
case 'tif':
case 'tiff':
case 'webp':
return Resource.LOAD_TYPE.IMAGE;
default:
return Resource.LOAD_TYPE.XHR;
}
};
/**

@@ -551,0 +575,0 @@ * Determines the mime type of an XHR request based on the responseType of

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc