1 | /*
|
---|
2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
---|
3 | */
|
---|
4 |
|
---|
5 | "use strict";
|
---|
6 |
|
---|
7 | const RuntimeModule = require("../RuntimeModule");
|
---|
8 | const Template = require("../Template");
|
---|
9 |
|
---|
10 | /** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
|
---|
11 |
|
---|
12 | class ChunkPrefetchFunctionRuntimeModule extends RuntimeModule {
|
---|
13 | /**
|
---|
14 | * @param {string} childType TODO
|
---|
15 | * @param {string} runtimeFunction TODO
|
---|
16 | * @param {string} runtimeHandlers TODO
|
---|
17 | */
|
---|
18 | constructor(childType, runtimeFunction, runtimeHandlers) {
|
---|
19 | super(`chunk ${childType} function`);
|
---|
20 | this.childType = childType;
|
---|
21 | this.runtimeFunction = runtimeFunction;
|
---|
22 | this.runtimeHandlers = runtimeHandlers;
|
---|
23 | }
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * @returns {string} runtime code
|
---|
27 | */
|
---|
28 | generate() {
|
---|
29 | const { runtimeFunction, runtimeHandlers } = this;
|
---|
30 | const { runtimeTemplate } = this.compilation;
|
---|
31 | return Template.asString([
|
---|
32 | `${runtimeHandlers} = {};`,
|
---|
33 | `${runtimeFunction} = ${runtimeTemplate.basicFunction("chunkId", [
|
---|
34 | // map is shorter than forEach
|
---|
35 | `Object.keys(${runtimeHandlers}).map(${runtimeTemplate.basicFunction(
|
---|
36 | "key",
|
---|
37 | `${runtimeHandlers}[key](chunkId);`
|
---|
38 | )});`
|
---|
39 | ])}`
|
---|
40 | ]);
|
---|
41 | }
|
---|
42 | }
|
---|
43 |
|
---|
44 | module.exports = ChunkPrefetchFunctionRuntimeModule;
|
---|