Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F101103765
ChunkPrefetchTriggerRuntimeModule.js
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Feb 5, 19:01
Size
1 KB
Mime Type
text/x-c++
Expires
Fri, Feb 7, 19:01 (2 d)
Engine
blob
Format
Raw Data
Handle
24090360
Attached To
rOACCT Open Access Compliance Check Tool (OACCT)
ChunkPrefetchTriggerRuntimeModule.js
View Options
/*
MIT License http://www.opensource.org/licenses/mit-license.php
*/
"use strict";
const RuntimeGlobals = require("../RuntimeGlobals");
const RuntimeModule = require("../RuntimeModule");
const Template = require("../Template");
/** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
class ChunkPrefetchTriggerRuntimeModule extends RuntimeModule {
/**
* @param {string} childType TODO
* @param {string} runtimeFunction TODO
* @param {Object} chunkMap map from chunk to
* @param {boolean} afterChunkLoad true: start after chunk has been loaded, false: start after chunk loading has started
*/
constructor(childType, runtimeFunction, chunkMap, afterChunkLoad) {
super(`chunk ${childType} trigger`, RuntimeModule.STAGE_TRIGGER);
this.childType = childType;
this.runtimeFunction = runtimeFunction;
this.chunkMap = chunkMap;
this.afterChunkLoad = afterChunkLoad;
}
/**
* @returns {string} runtime code
*/
generate() {
const { childType, runtimeFunction, chunkMap, afterChunkLoad } = this;
const { runtimeTemplate } = this.compilation;
const body = [
"var chunks = chunkToChildrenMap[chunkId];",
"for (var i = 0; Array.isArray(chunks) && i < chunks.length; i++) {",
Template.indent(`${runtimeFunction}(chunks[i]);`),
"}"
];
return Template.asString([
chunkMap
? Template.asString([
`var chunkToChildrenMap = ${JSON.stringify(chunkMap, null, "\t")};`,
`${RuntimeGlobals.ensureChunkHandlers}.${childType} = ${
afterChunkLoad
? runtimeTemplate.basicFunction("chunkId, promises", [
`Promise.all(promises).then(${runtimeTemplate.basicFunction(
"",
body
)});`
])
: runtimeTemplate.basicFunction("chunkId", body)
};`
])
: `// no chunks to automatically ${childType} specified in graph`
]);
}
}
module.exports = ChunkPrefetchTriggerRuntimeModule;
Event Timeline
Log In to Comment