Skip to content

Instantly share code, notes, and snippets.

@joshthecoder
Last active August 29, 2015 14:11
Show Gist options
  • Save joshthecoder/87bb9ab99667dce02bbe to your computer and use it in GitHub Desktop.
Save joshthecoder/87bb9ab99667dce02bbe to your computer and use it in GitHub Desktop.
Flux stores and components decoupled w/ immutable JS.
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