Last active
November 28, 2019 04:47
-
-
Save lmeyerov/84f63f2432243c73eb9fc2f5d0e9f27a to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Flapjax stopwatch demo</title> | |
<link rel="stylesheet" href="styles.css"/> | |
<script type="text/javascript" src="https://www.flapjax-lang.org/download/flapjax-2.1.js"></script> | |
<script type="text/javascript"> | |
//Written in the React style with Flapjax as the only dependency | |
class Stopwatch { | |
// {resetsE: EventStream<ClickEvent> -> () | |
constructor ({resetsE}) { | |
//Behavior<number> | |
const nowB = timerB(50); | |
this.state = { | |
//Behavior<number> | |
stopwatchTimeB: | |
nowB.liftB( | |
(lastClicked, now) => (now - lastClicked), | |
resetsE | |
.snapshotE(nowB) | |
.startsWith(nowB.valueNow())) | |
}; | |
} | |
// () -> Behavior<DOM> | |
render() { | |
//Behavior<DOM> | |
const labelB = | |
this.state.stopwatchTimeB | |
.liftB((time) => `Elapsed: ${Math.round(time/1000)}s`) | |
//Behavior<DOM> | |
return DIV(H3({className: 'stopwatch'}, labelB)); | |
} | |
}; | |
function wire() { | |
// Behavior<DOM> | |
const myComponentB = | |
DIV(H1('Flapjax Demo'), | |
(new Stopwatch({resetsE: $E('resetBtn','click')})).render()); | |
insertDomB(myComponentB, "myComponent"); | |
} | |
</script> | |
</head> | |
<body onload="wire();"> | |
<div><div id="myComponent"/></div> | |
<input id="resetBtn" type="button" value="Reset"/> | |
</body> | |
</html> |
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
console.log('Hello World!'); |
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
input, .stopwatch { | |
padding: 0.5em; | |
} | |
.stopwatch { | |
color: #f30; | |
background: white; | |
border: 2px solid #f30; | |
display: inline-block; | |
} | |
input { | |
text-transform: uppercase; | |
font-weight: bold; | |
background: #FFF; | |
color: #000; | |
border: 2px solid black; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment