-
Notifications
You must be signed in to change notification settings - Fork 583
/
async.html
58 lines (50 loc) · 1.03 KB
/
async.html
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
<!DOCTYPE html>
<html>
<head>
<title>Async Generators Demo</title>
<style>
body {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
#box {
position: absolute;
left: 0;
top: 0;
white-space: nowrap;
border-radius: 5px;
text-shadow: 0 0 5px yellow;
font: 25px sans-serif;
text-align: center;
line-height: 22px;
letter-spacing: -2px;
}
</style>
<script src="../bin/BrowserSystem.js"></script>
<script>
System.loadScriptTypeModule();
</script>
<script type="module" traceurOptions="--async-functions --async-generators --for-on">
import Observable from './resources/Observable.js';
async function* coordinates() {
for (let event on Observable.fromEvent(window, 'mousemove')) {
yield {x: event.clientX, y: event.clientY};
}
}
async function followMouse() {
var box = document.getElementById('box');
for (let {x, y} on coordinates()) {
box.style.left = x + 'px';
box.style.top = y + 'px';
}
}
followMouse();
</script>
</head>
<body>
<div id="box">Traceur<br>Rocks!</div>
</body>
</html>