Skip to content

Commit 6377152

Browse files
committed
site: tidy repl example loading and fix race condition (sveltejs#2313)
1 parent d1536b2 commit 6377152

File tree

1 file changed

+17
-26
lines changed

1 file changed

+17
-26
lines changed

site/src/routes/repl/index.svelte

+17-26
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@
1010

1111
<script>
1212
import { onMount } from 'svelte';
13-
import { locate } from 'locate-character';
1413
import { process_example } from '../../components/Repl/process_example.js';
1514
import AppControls from './_components/AppControls/index.svelte';
1615
import Repl from '../../components/Repl/index.svelte';
1716
18-
export let version, example, gist_id;
19-
20-
console.log({ example });
17+
export let version;
18+
export let example;
19+
export let gist_id;
2120
2221
let repl;
2322
let gist;
@@ -52,7 +51,7 @@
5251
relaxed = false;
5352
fetch(`gist/${gist_id}`).then(r => r.json()).then(data => {
5453
gist = data;
55-
const { id, description, files } = data;
54+
const { description, files } = data;
5655
5756
name = description;
5857
@@ -84,36 +83,28 @@
8483
8584
repl.set({ components });
8685
});
87-
}
88-
});
86+
} else {
87+
relaxed = true;
88+
fetch(`examples/${example}.json`).then(async response => {
89+
if (response.ok) {
90+
const data = await response.json();
8991
90-
function load_example(slug) {
91-
console.log(`loading ${slug}`);
92+
name = data.title;
9293
93-
relaxed = true;
94-
fetch(`examples/${slug}.json`).then(async response => {
95-
if (response.ok) {
96-
const data = await response.json();
97-
98-
name = data.title;
99-
100-
const components = process_example(data.files);
101-
repl.set({ components });
94+
const components = process_example(data.files);
95+
repl.set({ components });
10296
103-
gist = null;
104-
}
105-
});
106-
}
97+
gist = null;
98+
}
99+
});
100+
}
101+
});
107102
108103
function handle_fork(event) {
109104
example = null;
110105
gist = event.detail.gist;
111106
gist_id = gist.id;
112107
}
113-
114-
$: if (process.browser && example) {
115-
load_example(example);
116-
}
117108
</script>
118109

119110
<style>

0 commit comments

Comments
 (0)