Last active
August 1, 2016 21:45
-
-
Save tannerlinsley/ee83e749cb142291e4638cb717af96cb to your computer and use it in GitHub Desktop.
This file contains 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
// Yep, that's all you have to import | |
import { Render, State, Component } from 'jumpsuit' | |
// Create a state and with some actions | |
const CounterState = State('counter', { | |
// Initial State | |
initial: { count: 0 }, | |
// Actions | |
increment (state, payload) { | |
return { count: ++state.count } | |
}, | |
decrement (state, payload) { | |
return { count: --state.count } | |
}, | |
}) | |
// Create a component | |
const Counter = Component({ | |
render() { | |
return ( | |
<div> | |
<h1>{ this.props.counter.count }</h1> | |
<Button onClick={ this.increment }>Increment</Button> | |
<Button onClick={ this.decrement }>Decrement</Button> | |
</div> | |
) | |
}, | |
increment(){ | |
// Dispatch state actions | |
CounterState.increment() | |
}, | |
decrement(){ | |
// Dispatch state actions | |
CounterState.decrement() | |
}, | |
}, (state) => ({ | |
// Subscribe to the counter state (will be available via this.props.counter) | |
counter: state.counter | |
})) | |
// Render your app! | |
Render({counter: CounterState}, <Counter/>) |
This file contains 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>Jumpsuit Example</title> | |
</head> | |
<body> | |
<div id="app"></div> | |
<script src="app.js"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment