Last active
August 29, 2015 14:11
-
-
Save joshthecoder/87bb9ab99667dce02bbe to your computer and use it in GitHub Desktop.
Flux stores and components decoupled w/ immutable JS.
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
var Actions = Flux.createActions( | |
INCR_COUNT, DECR_COUNT | |
); | |
var CountStore = Flux.createStore( | |
INCR_COUNT: (_, state) => state.update('count', count => count + 1) | |
DECR_COUNT: (_, state) => state.update('count', count => count - 1) | |
); | |
var App = React.createClass({ | |
render: function () { | |
return ( | |
<div> | |
<h1>Count is {this.state.count}</h1> | |
<button onClick={Actions.INCR_COUNT}>Increment Count</button> | |
<button onClick={Actions.DECR_COUNT}>Decrement Count</button> | |
</div> | |
); | |
} | |
}); | |
Flux.render(<App />, {count: 0}, document.body); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment