site: tidy repl example loading and fix race condition (#2313)

pull/2315/head
Conduitry 6 years ago
parent d1536b21a2
commit 63771522d3

@ -10,14 +10,13 @@
<script> <script>
import { onMount } from 'svelte'; import { onMount } from 'svelte';
import { locate } from 'locate-character';
import { process_example } from '../../components/Repl/process_example.js'; import { process_example } from '../../components/Repl/process_example.js';
import AppControls from './_components/AppControls/index.svelte'; import AppControls from './_components/AppControls/index.svelte';
import Repl from '../../components/Repl/index.svelte'; import Repl from '../../components/Repl/index.svelte';
export let version, example, gist_id; export let version;
export let example;
console.log({ example }); export let gist_id;
let repl; let repl;
let gist; let gist;
@ -52,7 +51,7 @@
relaxed = false; relaxed = false;
fetch(`gist/${gist_id}`).then(r => r.json()).then(data => { fetch(`gist/${gist_id}`).then(r => r.json()).then(data => {
gist = data; gist = data;
const { id, description, files } = data; const { description, files } = data;
name = description; name = description;
@ -84,14 +83,9 @@
repl.set({ components }); repl.set({ components });
}); });
} } else {
});
function load_example(slug) {
console.log(`loading ${slug}`);
relaxed = true; relaxed = true;
fetch(`examples/${slug}.json`).then(async response => { fetch(`examples/${example}.json`).then(async response => {
if (response.ok) { if (response.ok) {
const data = await response.json(); const data = await response.json();
@ -104,16 +98,13 @@
} }
}); });
} }
});
function handle_fork(event) { function handle_fork(event) {
example = null; example = null;
gist = event.detail.gist; gist = event.detail.gist;
gist_id = gist.id; gist_id = gist.id;
} }
$: if (process.browser && example) {
load_example(example);
}
</script> </script>
<style> <style>

Loading…
Cancel
Save