-
-
Save mikaelbr/e1c8eccb2b4aa6aa71d9 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
var component = require('omniscient'); | |
var React = require('react'); | |
var immstruct = require('immstruct'); | |
// With start time | |
var structure = immstruct({ startTime: new Date(), currentTime: new Date() }); | |
var Timer = component(function (props) { | |
// Or swap to have time until. | |
return React.DOM.h1({}, 'MS since start: ' + (props.cursor.get('currentTime') - props.cursor.get('startTime')) ); | |
}); | |
var render = function () { | |
React.render(Timer(structure.cursor()), document.body); | |
}; | |
render(); | |
structure.on('swap', render); | |
setInterval(function () { | |
structure.cursor('currentTime').update(function () { | |
return new Date(); | |
}); | |
}, 1000 * 60); // Update every minute |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment