Last active
March 9, 2017 09:42
-
-
Save stuf/fca5d17608abb187a6505c10b0504ba1 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
import React from 'karet'; | |
import Kefir from 'kefir'; | |
const tick = Kefir.interval(1000, 1); | |
const Timer = ({ start = 0 }) => | |
<div> | |
Seconds: {tick.scan((total, i) => total + i, start)} | |
</div>; |
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
<timer> | |
<p>Seconds Elapsed: { time }</p> | |
<script> | |
this.time = opts.start || 0 | |
tick() { | |
this.update({ time: ++this.time }) | |
} | |
var timer = setInterval(this.tick, 1000) | |
this.on('unmount', function() { | |
clearInterval(timer) | |
}) | |
</script> | |
</timer> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment