Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: simplify spec loading in docs with async and show loading errors #9207

Merged
merged 6 commits into from
Jan 22, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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