just some little testing of json loading

This commit is contained in:
Blue 2023-09-10 13:39:53 -03:00
parent 9b04a90b53
commit edc489ab1a
Signed by: blue
GPG Key ID: 9B203B252A63EE38
5 changed files with 39 additions and 8 deletions

19
node.js
View File

@ -350,13 +350,20 @@ function executeLoad (/*String*/path, /*LoadingFile*/loadingFile) {
setTimeout(boundError, 0);
}
break;
case Type.json:
try {
const json = require("./" + path);
this._loadedFiles.add(path);
setTimeout(onLoaded.bind(this, path, json), 0);
} catch (e) {
this._errors.set(path, e);
setTimeout(boundError, 0);
}
break;
case Type.css:
setTimeout(boundLoad, 0); //todo just for now, don't know what to do yet with css here
//getStylesheetWithTag(path, boundLoad, boundError, this._config.seed);
break;
case Type.json:
//getByXHR(path, boundLoad, boundError, "json", this._config.seed);
break;
case Type.binary:
//getByXHR(path, boundLoad, boundError, "arraybuffer", this._config.seed);
break;
@ -375,9 +382,9 @@ function notifyProgressSubscribers() {
}
}
function onLoaded(/*String*/path, /*HTMLScriptElement*/event) {
function onLoaded(/*String*/path, /*any*/value) {
if (this._moduleErrors.length)
return onModuleError.call(this, path, event);
return onModuleError.call(this, path, value);
const loading = this._loadingFiles.get(path);
this._loadedFiles.add(path);
@ -385,7 +392,7 @@ function onLoaded(/*String*/path, /*HTMLScriptElement*/event) {
case Type.json:
case Type.binary:
case Type.text:
this._loadedAssets.set(loading.originalName, event.target.response);
this._loadedAssets.set(loading.originalName, value);
break;
}
loading.callSuccessHandlers(callCallback, this);

View File

@ -33,6 +33,13 @@ function test () {
log("Value returned from additional module is correct");
else
log("Value returned from additional module is \"" + module + "\", which is incorrect");
const json = mimicry.getAsset("simple");
if (json instanceof Object && json.I === "am")
log("loaded by one of the modules asset (json) is present and valid");
else
log("loaded by one of the modules asset (json) is not present or invalid");
});
log("Successfully launched Mimicry empty module");
} catch (e) {

View File

@ -28,6 +28,12 @@ function test () {
log("Value returned from additional module is correct");
else
log("Value returned from additional module is \"" + module + "\", which is incorrect");
const json = mimicry.getAsset("simple");
if (json instanceof Object && json.I === "am")
log("loaded by one of the modules asset (json) is present and valid");
else
log("loaded by one of the modules asset (json) is not present or invalid");
});
log("Successfully launched Mimicry empty module");
} catch (e) {

View File

@ -1,7 +1,8 @@
"use strict";
mimicry.module([
"terminalModule",
"simple", Mimicry.Type.json,
"background", Mimicry.Type.css
], function (global, [terminalModule]) {
return terminalModule === "terminal";
], function (global, [terminalModule, simple]) {
return terminalModule === "terminal" && simple.a[4] === 115;
});

10
test/simple.json Normal file
View File

@ -0,0 +1,10 @@
{
"I": "am",
"a": [
"simple",
true,
true,
"json",
115
]
}