move app logic into templates (#444)

This commit is contained in:
Rich Harris
2018-09-30 10:30:00 -04:00
parent ff24877d8f
commit e30842caa8
19 changed files with 661 additions and 618 deletions

View File

@@ -0,0 +1,14 @@
import { manifest, load_component } from "../app";
export default function prefetchRoutes(pathnames: string[]) {
if (!manifest) throw new Error(`You must call init() first`);
return manifest.pages
.filter(route => {
if (!pathnames) return true;
return pathnames.some(pathname => route.pattern.test(pathname));
})
.reduce((promise: Promise<any>, route) => promise.then(() => {
return Promise.all(route.parts.map(part => part && load_component(part.component)));
}), Promise.resolve());
}