Created
October 17, 2014 23:19
-
-
Save spoike/7604729477e99246b89e to your computer and use it in GitHub Desktop.
Example from http://christianalfoni.github.io/javascript/2014/08/20/react-js-and-flux.html rewritten to use react and reflux
This file contains hidden or 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
/** @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