Skip to content

Commit

Permalink
refactor: simplify spec loading in docs with async
Browse files Browse the repository at this point in the history
  • Loading branch information
domoritz committed Dec 14, 2023
1 parent 12788a5 commit 93941f3
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions site/static/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,24 +108,20 @@ 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');
if (name) {
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');
}
Expand Down

0 comments on commit 93941f3

Please sign in to comment.