https://github.com/scriptollc/barracks-react
Flux off even faster!
https://github.com/scriptollc/barracks-react
Last synced: 11 months ago
JSON representation
Flux off even faster!
- Host: GitHub
- URL: https://github.com/scriptollc/barracks-react
- Owner: scriptoLLC
- License: other
- Created: 2016-08-30T22:28:38.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2017-06-21T15:22:02.000Z (almost 9 years ago)
- Last Synced: 2025-07-26T16:22:06.135Z (11 months ago)
- Language: JavaScript
- Size: 25.4 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# barracks-react
An action dispatcher for React that provides for unidirectional dataflows.
Intended to be very small and provide a small amount of cognative overhead in
providing an "actions up, data down" type model for React. Built on top of
[barracks](https://github.com/yoshuawuyts/barracks).
## Usage
```js
const React = require('react')
const ReactDOM = require('react-dom')
const bearact = require('./')
const model = {
namespace: 'example',
state: {
hello: ''
},
reducers: {
setHello: (state, data) => ({hello: data.value})
}
}
const Main = React.createClass({
handleChange: function (evt) {
this.props.send('setHello', {value: evt.target.value})
},
render: function () {
return React.createElement('div', {}, [
React.createElement('h1', {}, `Hello, ${this.props.model.hello}`),
React.createElement('br', {}, null),
React.createElement('input', {value: this.props.model.hello, onChange: (evt) => this.handleChange(evt)}, null)])
}
})
const main = React.createElement(bearact(Main, model))
const mount = document.createElement('div')
document.body.appendChild(mount)
ReactDOM.render(main, mount)
```
## License
Copyright © 2016 Scripto, licenced under the Apache-2.0 license