Skip to content

Commit 104d7a1

Browse files
committed
Added start of the new Loader.
1 parent e34d53a commit 104d7a1

5 files changed

Lines changed: 140 additions & 0 deletions

File tree

v3/src/loader/Loader.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
var Set = require('../structs/Set');
2+
var XHRSettings = require('./XHRSettings');
3+
4+
var Loader = function ()
5+
{
6+
// Move to a 'setURL' method
7+
this.baseURL = '';
8+
this.path = '';
9+
10+
this.tag = '';
11+
12+
this.enableParallel = true;
13+
14+
this.maxParallelDownloads = 4;
15+
16+
// xhr specific global settings (can be overridden on a per-file basis)
17+
this.xhr = XHRSettings();
18+
19+
this.crossOrigin = undefined;
20+
21+
this.list = new Set();
22+
this.inflight = new Set();
23+
this.failed = new Set();
24+
this.queue = new Set();
25+
this.storage = new Set();
26+
27+
this._state = 'PENDING';
28+
};
29+
30+
Loader.prototype.contructor = Loader;
31+
32+
Loader.prototype = {
33+
34+
add: function ()
35+
{
36+
37+
}
38+
39+
};
40+
41+
module.exports = Loader;

v3/src/loader/MergeXHRSettings.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
var XHRSettings = require('./XHRSettings');
2+
3+
// Takes two XHR Objects and creates a new object
4+
5+
// The new object is based on global initially, but any setting in
6+
// local overrides the global value.
7+
8+
var MergeXHRSettings = function (global, local)
9+
{
10+
var output = (global === undefined) ? XHRSettings() : Object.assign(global);
11+
12+
if (local)
13+
{
14+
for (var setting in local)
15+
{
16+
if (local[setting] !== undefined)
17+
{
18+
output[setting] = local[setting];
19+
}
20+
}
21+
}
22+
23+
return output;
24+
25+
};
26+
27+
module.exports = MergeXHRSettings;

v3/src/loader/XHRLoader.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
var MergeXHRSettings = require('./MergeXHRSettings');
2+
3+
var XHRLoader = function (file, globalXHRSettings)
4+
{
5+
var config = MergeXHRSettings(globalXHRSettings, file.xhr);
6+
7+
var xhr = new XMLHttpRequest();
8+
9+
xhr.open('GET', file.src, config.async, config.user, config.password);
10+
11+
xhr.responseType = file.xhr.responseType;
12+
xhr.timeout = config.timeout;
13+
14+
if (config.header && config.headerValue)
15+
{
16+
xhr.setRequestHeader(config.header, config.headerValue);
17+
}
18+
19+
if (config.overrideMimeType)
20+
{
21+
xhr.overrideMimeType(config.overrideMimeType);
22+
}
23+
24+
// After a successful request, the xhr.response property will contain the requested data as a DOMString, ArrayBuffer, Blob, or Document (depending on what was set for responseType.)
25+
26+
xhr.onload = file.onLoad(xhr);
27+
xhr.onerror = file.onError(xhr);
28+
29+
xhr.send();
30+
31+
return xhr;
32+
};
33+
34+
module.exports = XHRLoader;

v3/src/loader/XHRSettings.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Creates an XHRSettings Object with default values
2+
3+
var XHRSettings = function (responseType, async, user, password, timeout)
4+
{
5+
if (responseType === undefined) { responseType = ''; }
6+
if (async === undefined) { async = true; }
7+
if (user === undefined) { user = ''; }
8+
if (password === undefined) { password = ''; }
9+
if (timeout === undefined) { timeout = 0; }
10+
11+
// Before sending a request, set the xhr.responseType to "text", "arraybuffer", "blob", or "document", depending on your data needs. Note, setting xhr.responseType = '' (or omitting) will default the response to "text".
12+
13+
return {
14+
15+
// Ignored by the Loader, only used by File.
16+
responseType: responseType,
17+
18+
async: async,
19+
20+
// credentials
21+
user: user,
22+
password: password,
23+
24+
// timeout in ms (0 = no timeout)
25+
timeout: timeout,
26+
27+
// setRequestHeader
28+
header: undefined,
29+
headerValue: undefined,
30+
31+
// overrideMimeType
32+
overrideMimeType: undefined
33+
34+
};
35+
36+
};
37+
38+
module.exports = XHRSettings;

v3/src/loader/filetypes/Image.js

Whitespace-only changes.

0 commit comments

Comments
 (0)