Created
June 5, 2015 23:56
-
-
Save iksarfo/c466bd62a7f8268bb156 to your computer and use it in GitHub Desktop.
react.inc
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
<html> | |
<head> | |
<title>react.inc</title> | |
</head> | |
<body> | |
<div id="bobCounter"></div> | |
<div id="bobButton"></div> | |
</body> | |
<!-- The core React library --> | |
<script src="https://fb.me/react-0.13.3.js"></script> | |
<!-- In-browser JSX transformer, remove when pre-compiling JSX. --> | |
<script src="https://fb.me/JSXTransformer-0.13.3.js"></script> | |
<script src="./node_modules/reflux/dist/reflux.js"></script> | |
<script type="text/jsx"> | |
var Actions = Reflux.createActions(["increment"]); | |
var incStore = Reflux.createStore({ | |
listenables: [Actions], | |
getInitialState: function() { | |
return this.val = 0; | |
}, | |
increment: function() { | |
this.val = this.val + 1; | |
this.trigger(this.val); | |
} | |
}) | |
var DisplayBob = React.createClass({ | |
mixins: [Reflux.connect(incStore, "incrementing")], | |
render: function() { | |
return (<span>{this.state.incrementing}</span>); | |
} | |
}); | |
var ButtonBob = React.createClass({ | |
render: function() { | |
return (<button onClick={function() { Actions.increment()} }>Bob</button>); | |
} | |
}) | |
React.render( | |
<h1><DisplayBob /></h1>, | |
document.getElementById('bobCounter') | |
); | |
React.render(<ButtonBob/>, document.getElementById('bobButton')); | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment