-
-
Notifications
You must be signed in to change notification settings - Fork 522
Expand file tree
/
Copy pathexamples.js
More file actions
76 lines (73 loc) 路 1.58 KB
/
Copy pathexamples.js
File metadata and controls
76 lines (73 loc) 路 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import simpleCounterExample from './examples/simple-counter.txt?url';
import counterWithHtmExample from './examples/counter-with-htm.txt?url';
import todoExample from './examples/todo-list.txt?url';
import todoExampleSignal from './examples/todo-list-signal.txt?url';
import repoListExample from './examples/github-repo-list.txt?url';
import contextExample from './examples/context.txt?url';
import spiralExample from './examples/spiral.txt?url';
export const EXAMPLES = [
{
name: 'Simple Counter',
slug: 'counter',
url: simpleCounterExample
},
{
name: 'Todo List',
slug: 'todo',
url: todoExample
},
{
name: 'Todo List (Signals)',
slug: 'todo-list-signals',
url: todoExampleSignal
},
{
name: 'Github Repo List',
slug: 'github-repo-list',
url: repoListExample
},
{
group: 'Advanced',
items: [
{
name: 'Counter using HTM',
slug: 'counter-htm',
url: counterWithHtmExample
},
{
name: 'Context',
slug: 'context',
url: contextExample
}
]
},
{
group: 'Animation',
items: [
{
name: 'Spiral',
slug: 'spiral',
url: spiralExample
}
]
}
];
export function getExample(slug, list = EXAMPLES) {
for (let i = 0; i < list.length; i++) {
let item = list[i];
if (item.group) {
let found = getExample(slug, item.items);
if (found) return found;
} else if (item.slug.toLowerCase() === slug.toLowerCase()) {
return item;
}
}
}
/**
* @param {string} slug
*/
export async function fetchExample(slug) {
const example = getExample(slug);
if (!example) return;
return await fetch(example.url).then(r => r.text());
}