(
basePath: string,
serializedResponse?: ReturnType<typeof fetch>,
opts?: {
/** Enable logging */
debug?: boolean;
/** Maximum number of simultaneous preload links */
P?: number;
/** Minimum probability for a bundle to be added to the preload queue */
Q?: number;
}
)
| 65 | |
| 66 | /** Used in browser */ |
| 67 | export const loadBundleGraph = ( |
| 68 | basePath: string, |
| 69 | serializedResponse?: ReturnType<typeof fetch>, |
| 70 | opts?: { |
| 71 | /** Enable logging */ |
| 72 | debug?: boolean; |
| 73 | /** Maximum number of simultaneous preload links */ |
| 74 | P?: number; |
| 75 | /** Minimum probability for a bundle to be added to the preload queue */ |
| 76 | Q?: number; |
| 77 | } |
| 78 | ) => { |
| 79 | if (opts) { |
| 80 | if ('d' in opts) { |
| 81 | config.$DEBUG$ = !!opts.d; |
| 82 | } |
| 83 | if ('P' in opts) { |
| 84 | config.$maxIdlePreloads$ = opts['P'] as number; |
| 85 | } |
| 86 | if ('Q' in opts) { |
| 87 | config.$invPreloadProbability$ = 1 - (opts['Q'] as number); |
| 88 | } |
| 89 | } |
| 90 | if (!isBrowser || basePath == null) { |
| 91 | return; |
| 92 | } |
| 93 | base = basePath; |
| 94 | |
| 95 | if (serializedResponse) { |
| 96 | serializedResponse |
| 97 | .then((r) => r.text()) |
| 98 | .then((text) => { |
| 99 | graph = parseBundleGraph(JSON.parse(text)); |
| 100 | const toAdjust: [BundleImport, number][] = []; |
| 101 | for (const [name, deps] of graph.entries()) { |
| 102 | const bundle = getBundle(name)!; |
| 103 | bundle.$deps$ = deps; |
| 104 | if (bundle.$inverseProbability$ < 1) { |
| 105 | toAdjust.push([bundle, bundle.$inverseProbability$]); |
| 106 | bundle.$inverseProbability$ = 1; |
| 107 | } |
| 108 | } |
| 109 | config.$DEBUG$ && |
| 110 | log(`parseBundleGraph got ${graph.size} bundles, adjusting ${toAdjust.length}`); |
| 111 | for (const [bundle, inverseProbability] of toAdjust) { |
| 112 | adjustProbabilities(bundle, inverseProbability); |
| 113 | } |
| 114 | trigger(); |
| 115 | }) |
| 116 | .catch(console.warn); |
| 117 | } |
| 118 | }; |
| 119 | |
| 120 | /** Used during SSR */ |
| 121 | export const initPreloader = ( |
nothing calls this directly
no test coverage detected
searching dependent graphs…