From 304a8ac4a28194c8af0eb7999833f315cb53cac3 Mon Sep 17 00:00:00 2001 From: Tuukka Hastrup Date: Wed, 27 May 2020 16:04:36 +0300 Subject: [PATCH] Delay Planner.js import until first plan is calculated --- src/planner.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/planner.ts b/src/planner.ts index e0f2e9e8..91b88e0a 100644 --- a/src/planner.ts +++ b/src/planner.ts @@ -6,7 +6,7 @@ import { GeoJsonProperties, } from "geojson"; -import { Planner } from "./planner-config"; +// "./planner-config" (and PlannerJS) is imported dynamically by calculatePlan import { ElementWithCoordinates } from "./overpass"; @@ -206,11 +206,15 @@ export function geometryToGeoJSON( }; } -export default function calculatePlan( +export default async function calculatePlan( origin: [number, number], targets: Array, callback: (f: FeatureCollection) => void -): void { +): Promise { + const { Planner } = await import( + /* webpackChunkName: "planner-config" */ + "./planner-config" + ); targets.forEach((target) => { const planner = new Planner(); // XXX setProfileID requires URL to start with scheme, so guess