Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
js-csp/examples/web/mouse-events.html
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
47 lines (42 sloc)
1.5 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |