forked from coldemo/gallery.code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrank-async-generator.jsx
More file actions
45 lines (40 loc) · 1.12 KB
/
crank-async-generator.jsx
File metadata and controls
45 lines (40 loc) · 1.12 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
/** @jsx createElement */
// import {Context, createElement, Element} from "@bikeshaving/crank";
// import {renderer} from "@bikeshaving/crank/dom";
// await loadJs('https://unpkg.com/@bikeshaving/crank/umd/index.js');
await loadJs('https://unpkg.com/[email protected]/umd/index.js');
const {createElement, renderer} = Crank;
appendCss(`
#mountNode { padding: 20px }
`);
// https://github.com/bikeshaving/crank/tree/master/examples/async-generator
const mount = document.getElementById("mountNode");
const arr = [];
async function* List(
{elems},
) {
let i = 0;
for await ({elems} of this) {
i++;
if (i % 5 === 0) {
yield (<div>Loading {elems.length} items...</div>);
await new Promise((resolve) => setTimeout(resolve, 4000));
}
yield (
<ul>
{elems.map((i) => (
<li crank-key={i}>{i}</li>
))}
</ul>
);
await new Promise((resolve) => setTimeout(resolve, 500));
}
}
renderer.render(<List elems={arr} />, mount);
setInterval(() => {
arr.push(arr.length + 1);
if (arr.length > 30) {
arr.length = 0;
}
renderer.render(<List elems={arr} />, mount);
}, 1000);