Last active
August 29, 2015 14:26
-
-
Save benkeen/cac3e37e2e4d7fd866b7 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
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