Data-JPack
view release on metacpan or search on metacpan
share/js/02-chunkloader.js view on Meta::CPAN
try {
ChunkLoader == undefined;
}
catch(e){
class ChunkLoader extends ScriptLoader {
constructor(selfSrc){
super(selfSrc);
let parts=this.src.split("/");
parts.pop();
parts.pop();
parts.pop();
parts.pop();
parts.pop();
this.buildRoot=parts.join("/")+"/";
window.build_root=this.buildRoot;
//List of objects or callbacks to call as data is being loaded
this.manifest=[];
this.path_manifest={};
this.chunksExpected=100;
this.chunksLoaded=0;
this.tags={};
this.urlQueue=[];
this.urlMap={};
this.availableQueue=[];
this.working=0;
this.workingLimit=4;
this.resolver;
let scope=this;
this.ready=new Promise((resolve,reject)=>{
scope.resolver=resolve;
});
return this;
}
updateStatus(message,mode){
//console.log("UPDATE STATUS CALLED");
let e=new CustomEvent("JPACK_STATUS",{detail: {progress: parseInt(100*this.chunksLoaded/this.chunksExpected), message:message, mode:mode}});
window.dispatchEvent(e);
}
/**
* Load the pako.js into worker pool for delfate support
* This is actaully prencoded (no compression) for dynamic loading
*/
bootstrap(){
// Path is relative to this.buildRoot
let name="app/jpack/boot/00000000000000000000000000000000/00000000000000000000000000000000.jpack";
return this.queueChunkScript(name)
.then((data)=>{
let decoder=new TextDecoder("utf-8");
let string=decoder.decode(data);
return this.pool.addScriptBody(string)
.then(()=>{
// Unload scripts
this.unloadScript(this.buildRoot+name);
this.chunksLoaded++;
this.updateStatus("Boot Complete");
return Promise.resolve();
});
});
}
//This callback is executed from a chunk script to decode/decompress the data
//
decodeData(options, dataFunc){
( run in 0.856 second using v1.01-cache-2.11-cpan-39bf76dae61 )