Skip to content

Instantly share code, notes, and snippets.

@benkeen
Last active August 29, 2015 14:26
Show Gist options
  • Save benkeen/cac3e37e2e4d7fd866b7 to your computer and use it in GitHub Desktop.
Save benkeen/cac3e37e2e4d7fd866b7 to your computer and use it in GitHub Desktop.
var MyComponent = FauxtonAPI.createClass({
// this would contain the React.createClass() stuff like now. the FauxtonAPI wrapper would
// handle the instantiation for us
component: function (stores) {
return {
getInitialState: function () {
return getStateFromStores(this.props);
},
componentDidMount: function () {
stores.forEach(function (store) {
store.on('change', this.onChange, this);
}.bind(this));
},
componentWillUnmount: function () {
stores.forEach(function (store) {
store.off('change', this.onChange);
}.bind(this));
},
onChange: function () {
if (this.isMounted()) {
this.setState(getStateFromStores(this.props));
}
},
render: function () {
return (<Component {...this.props} {...this.state} />);
}
}
},
stores: [store1, store2],
getStoreState: function () {
return {
whatever: store1.getWhatever(),
somethingElse: store2.getSomethingElse()
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment