Skip to content

Instantly share code, notes, and snippets.

@mikaelbr
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikaelbr/e1c8eccb2b4aa6aa71d9 to your computer and use it in GitHub Desktop.
Save mikaelbr/e1c8eccb2b4aa6aa71d9 to your computer and use it in GitHub Desktop.
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