From 93941f309748e2105ae153aeb64822014a194441 Mon Sep 17 00:00:00 2001 From: Dominik Moritz Date: Thu, 14 Dec 2023 16:17:09 -0500 Subject: [PATCH] refactor: simplify spec loading in docs with async --- site/static/index.ts | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/site/static/index.ts b/site/static/index.ts index f359698165..77802d0ad0 100644 --- a/site/static/index.ts +++ b/site/static/index.ts @@ -108,7 +108,7 @@ export function embedExample($target: any, spec: TopLevelSpec, actions = true, t return view; } -function getSpec(el: d3.BaseType) { +async function getSpec(el: d3.BaseType) { const sel = select(el); const name = sel.attr('data-name'); const figureOnly = !!sel.attr('figure-only'); @@ -116,16 +116,12 @@ function getSpec(el: d3.BaseType) { const dir = sel.attr('data-dir'); const fullUrl = `${BASEURL}/examples/${dir ? `${dir}/` : ''}${name}.vl.json`; - fetch(fullUrl) - .then(response => { - response - .text() - .then(spec => { - renderExample(sel, spec, figureOnly); - }) - .catch(console.error); - }) - .catch(console.error); + try { + const spec = await (await fetch(fullUrl)).text(); + renderExample(sel, spec, figureOnly); + } catch (e) { + console.error(e); + } } else { console.error('No "data-name" specified to import examples from'); }