Created
October 17, 2014 13:46
-
-
Save aaronj1335/f9d80b6d89712d32733d 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
module.exports = { | |
listenTo: function(other, event, callback) { | |
other.on(event, callback, this); | |
this._eventEmitters = this._eventEmitters || []; | |
this._eventEmitters.push([other, event]); | |
}, | |
componentWillUnmount: function() { | |
(this._eventEmitters || []).forEach(function([other, event]) { | |
other.off(event, null, this); | |
}); | |
} | |
}; |
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 shortcodes = require('./../../data/shortcodes'); | |
var ListenTo = require('./../../util/listen-to'); | |
module.exports = createClass({ | |
displayName: 'MyComponent', | |
mixins: [ListenTo], | |
getInitialState: function() { | |
return { | |
models: shortcodes().toJSON() | |
}; | |
}, | |
componentDidMount: function() { | |
this.listenTo(shortcodes(), 'all', this.onEvent); | |
shortcodes().initialFetch(); | |
}, | |
onEvent: function() { | |
this.setState({models: shortcodes().toJSON()}); | |
}, | |
render: function() { | |
return /* ... */; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment