Skip to content

Instantly share code, notes, and snippets.

@relekang
Created December 1, 2015 14:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save relekang/2174238194dd2f337e18 to your computer and use it in GitHub Desktop.
Save relekang/2174238194dd2f337e18 to your computer and use it in GitHub Desktop.
Store mixin
export default React.createClass({
displayName: 'ExamplePage',
stores: [ExampleStore, OtherStore],
mixins: [StoreMixin],
render: function() {
return <h1>o/</h1>;
}
});
import _ from 'lodash';
export const StoreMixin = {
componentWillMount: function() {
_.each(this.stores, store => {
store.addChangeListener(this.onChange);
})
},
componentWillUnmount: function() {
_.each(this.stores, store => {
store.removeChangeListener(this.onChange);
})
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment