diff --git a/node.js b/node.js index bf2a21d..0260319 100644 --- a/node.js +++ b/node.js @@ -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); diff --git a/test/index.js b/test/index.js index 32feff5..fbbd78e 100644 --- a/test/index.js +++ b/test/index.js @@ -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) { diff --git a/test/main.js b/test/main.js index 9eea9c7..2e9667a 100644 --- a/test/main.js +++ b/test/main.js @@ -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) { diff --git a/test/module.js b/test/module.js index f2511b3..934bb24 100644 --- a/test/module.js +++ b/test/module.js @@ -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; }); \ No newline at end of file diff --git a/test/simple.json b/test/simple.json new file mode 100644 index 0000000..61d80a7 --- /dev/null +++ b/test/simple.json @@ -0,0 +1,10 @@ +{ + "I": "am", + "a": [ + "simple", + true, + true, + "json", + 115 + ] +} \ No newline at end of file