-
Notifications
You must be signed in to change notification settings - Fork 123
/
mouse-events.html
47 lines (42 loc) · 1.5 KB
/
mouse-events.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
<html>
<head>
<meta charset="UTF-8"></meta>
<title>Events</title>
<script type="text/javascript" src="../../dist/js-csp.min.js"></script>
</head>
<body>
<div id="display"></div>
<script type="text/javascript">
var el = document.getElementById("display");
function show(text) {
el.textContent = text;
console.log(text);
}
function noOp() {};
function firehose(element, eventName) {
var ch = csp.chan(csp.buffers.dropping(1));
element.addEventListener(eventName, function(event) {
csp.putAsync(ch, event, noOp);
});
return ch;
}
var moves = firehose(document.body, "mousemove");
csp.go(function*() {
for (;;) {
var event = yield csp.take(moves);
show(event.x + ":" + event.y);
for (;;) {
var result = yield csp.alts([moves, csp.timeout(50)]);
var value = result.value;
if (value === csp.CLOSED) {
show("STOP");
break;
}
event = value;
show(event.x + ":" + event.y);
}
}
});
</script>
</body>
</html>