Skip to content

Instantly share code, notes, and snippets.

@garlicnation
Created September 21, 2016 21:41
Show Gist options
  • Save garlicnation/5dc869279b253a03048ecbfbaa41595a to your computer and use it in GitHub Desktop.
Save garlicnation/5dc869279b253a03048ecbfbaa41595a to your computer and use it in GitHub Desktop.
1) Given N endpoints, build map from endpoint -> dependency[]
2) Given endpoint -> dep map, build dep -> endpoint[] map
3) Apply user-provided function to the results from step 2 to build bundle manifest
4) Bundle endpoints according to map from step 3
bundle(["shop-app.html", "shop-list.html", "shop-cart.html"], analyzer, appShellHeuristic("end1.html"))
async bundle(url: string|string[], orchestrator?: BundleOrchestrator): Promise<DocumentCollection> {}
interface BundleManifest {
// Map from entry point to contained files. The files in the map's // values are unique across the manifest.
Map<string, string[]>: entries
}
interface BundleOrchestrator {
(endpoints: string[], depsIndex: DepsIndex): BundleManifest
}
function sharedHeuristic(string?: appShell): BundleOrchestrator {
return function(endpoints: string[], depsIndex: DepsIndex): BundleManifest {
const manifest = new Map();
const sharedDependencies = getSharedDeps(endpoints, depsIndex, sharingThreshold);
manifest.set("shared.html", sharedDependencies)
return manifest;
}
}
function appShellHeuristic(string?: appShell): BundleOrchestrator {
return function(endpoints: string[], depsIndex: DepsIndex): BundleManifest {
const manifest = new Map();
const sharedDependencies = getSharedDeps(endpoints, depsIndex, sharingThreshold);
if (appShell) {
// assign sharedDependencies to appShell
manifest.get(appShell).add(sharedDependencies)
} else {
// Create a shared.html file that gets all shared dependencies
}
}
}
function myCustomBuild(appShell) {
const heuristic = appShellHeuristic(appShell);
return function(endpoints, depsIndex) {
let manifest = heuristic(endpoints, depsIndex);
manifest.transformArbitrarily();
return manifest;
}
}
/**
lazy dependency: ->
eager depdendency: =>
shop-app.html -> shop-list.html
shop-app.html -> shop-cart.html
shop-app.html -> shop-item.html
shop-app.html => shop-home.html
shop-list.html -> lazy-resources.html
shop-cart.html -> lazy-resources.html
shop-item.html -> lazy-resources.html
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment