Skip to content

Instantly share code, notes, and snippets.

@mikker
Last active September 2, 2015 05:58
Show Gist options
  • Save mikker/b5e28aea12fdb4238f48 to your computer and use it in GitHub Desktop.
Save mikker/b5e28aea12fdb4238f48 to your computer and use it in GitHub Desktop.
A simple countdown timer example in ES6, React and Reflux.
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