Skip to content

Instantly share code, notes, and snippets.

@spoike
Created October 17, 2014 23:19
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 spoike/7604729477e99246b89e to your computer and use it in GitHub Desktop.
Save spoike/7604729477e99246b89e to your computer and use it in GitHub Desktop.
/** @jsx React.DOM */
var React = require('react'),
Reflux = require('reflux'),
toggle = Reflux.createAction(),
userStore = Reflux.createStore({
init: function() {
this.notify = false;
this.listenTo(toggle, this.onToggle);
},
onToggle: function(flag) {
this.notify = flag;
this.trigger(flag);
}
});
var Checkbox = React.createClass({
mixins: [Reflux.ListenerMixin],
componentDidMount: function() {
this.listenTo(userStore, this.onChange);
},
onChange: function(val) {
this.setState({notify: val});
},
notify: function() {
toggle(this.refs.checkbox.getDOMNode().checked);
},
render: function() {
return (<input ref="checkbox" type="checkbox" checked={this.state.notify} onChange={this.notify}>)
}
});
React.renderComponent(<Checkbox/>, document.body);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment