mitos
v1.0.3
Published
Makes JavaScript bundles that can be appended to
Downloads
7
Readme
Mitos
Commands
@import <path>@
imports a .dna file from the path specified
@retrieve <data property>@
splices data into the JavaScript file as inserted in the config.
@params <arguments>@
adds arguments into the function wrapper
Setup
Server: Configuration
require("mitos").config({
"data": {
key1: "word"
},
"import paths": [
require("paths")["assets"] + "/dna/",
require("paths")["assets"] + "/other-dna/"
]
});
Server: Make (& Send) First Bundle
require("mitos")["get package 1"]({
"query": "import entry_point/first_page", //* required, just like the query, but w/o at symbols
"launch params": ["start"] //* optional, these are passed in as arguments to the function that initiates the application
}, function(bundle) {
var script = "<script>" + bundle + "<script>";
// e.g. add script to html doc and send that to client
});
Client: Request additional JavaScript
Essentially this makes a POST request that includes the manifest of files that the client currently has, so that subsequent bundles can utilize these files
function mitos_request_subsequent_bundle(options) {
var url = options.url;
var data = options.data || null;
var request = new XMLHttpRequest();
var manifest = window["manifest"];
request.onreadystatechange = function() {
if (request.readyState == 4 && request.status == 200) {
var response = request.responseText;
var scriptStart;
var launch;
(function() {
var number = "";
if (response.substring(0,1) === "*") {
for (var i = 1; i < response.length; i++) {
var char = response.substring(i,i+1);
if (char === "*") {
if (number !== -1) {
launch = parseInt(number);
scriptStart = i + 1;
return;
}
else {
console.error("launch number not provided");
}
}
else {
number = number + char;
}
}
}
else {
console.error("launch not found");
}
})();
var js = response.substring(scriptStart);
if (js.length > 0) {
var script = document.createElement("script");
script.text = js;
document.getElementById("sequences").appendChild(script);
}
window.bundle[launch](data);
}
};
request.open("POST", url, true);
request.send(JSON.stringify(manifest));
};
Server: Response to mitos_request_subsequent_bundle()
require("mitos")["get package 2+"]({
"query": "import entry_point/second_page",
"manifest": manifest,
"launch params": ["asdfasdfasdf", "asdfasdfasdf"]
}, function(bundle) {
response.write(bundle);
response.end();
});