Created
February 24, 2015 17:56
-
-
Save danielyogel/100cd98b01821ba16c88 to your computer and use it in GitHub Desktop.
forceUpdate for hipsters :-)
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 ModelEventsMixin = { | |
shouldComponentUpdate: () => false, | |
componentWillMount: function () { | |
var self = this; | |
this.modelsToListen.forEach(function (model_name) { | |
eventEmitter.addListener(model_name + '_model_update', self.listener); // PROBLEM if I hange listener to forceUpdate. | |
}); | |
}, | |
componentWillUnmount: function () { | |
var self = this; | |
this.modelsToListen.forEach(function (model_name) { | |
eventEmitter.removeListener(model_name + '_model_update', self.listener); | |
}); | |
} | |
}; | |
var Profile = React.createClass({ | |
mixins: [ModelEventsMixin], | |
modelsToListen: ['profile'], | |
listener: function () { | |
this.forceUpdate(); | |
}, | |
render: function () { | |
return ( | |
<div> | |
<ProfileLinks/> | |
<ProfileSidebar/> | |
</div> | |
); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how about