'Higher Order Component' for alt flux that controls the props of a wrapped component via stores.
Alt is an Isomorphic flux implementation.
Check out the API Reference for full in-depth alt docs. For a high-level walk-through on flux, take a look at the Getting Started guide.
// @todo Use real badges for this package.
/*
[](http://badge.fury.io/js/alt)
[](http://travis-ci.org/goatslacker/alt)
[](https://coveralls.io/r/goatslacker/alt)
[](https://david-dm.org/goatslacker/alt)
[](https://www.npmjs.com/package/alt)
[](http://js.org)
*/
Expects the Component to have two static methods:
- getStores(): Should return an array of stores.
- getPropsFromStores(props): Should return the props from the stores.
Using old React.createClass() style:
const MyComponent = React.createClass({
statics: {
getStores(props) {
return [myStore]
},
getPropsFromStores(props) {
return myStore.getState()
}
},
render() {
// Use this.props like normal ...
}
})
MyComponent = connectToStores(MyComponent)
Using ES6 Class:
class MyComponent extends React.Component {
static getStores(props) {
return [myStore]
}
static getPropsFromStores(props) {
return myStore.getState()
}
render() {
// Use this.props like normal ...
}
}
MyComponent = connectToStores(MyComponent)
Using ES7 Decorators (proposal, stage 0):
@connectToStores
class MyComponent extends React.Component {
static getStores(props) {
return [myStore]
}
static getPropsFromStores(props) {
return myStore.getState()
}
render() {
// Use this.props like normal ...
}
}
A great explanation of the merits of higher order components can be found at http://bit.ly/1abPkrP