Last active
September 2, 2015 05:58
-
-
Save mikker/b5e28aea12fdb4238f48 to your computer and use it in GitHub Desktop.
A simple countdown timer example in ES6, React and Reflux.
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 'react' | |
import Reflux from 'reflux' | |
var TimeActions = Reflux.createActions(['tick']) | |
var TimeStore = Reflux.createStore({ | |
listenables: [TimeActions], | |
onTick: function(tick) { | |
this.trigger(tick); | |
if (tick === 0) return; | |
setTimeout(() => TimeActions.tick(tick - 1), 1000); | |
} | |
}) | |
var Watch = React.createClass({ | |
mixins: [Reflux.connect(TimeStore, 'tick')], | |
componentDidMount: function() { | |
TimeActions.tick(this.props.ticks) | |
}, | |
render: function() { | |
return ( | |
<h1>{this.state.tick}</h1> | |
) | |
} | |
}) | |
React.render(<Watch ticks={10}></Watch>, document.body); | |
export default {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment