React.createClass({ getInitialState: function() { return { selection: 'none' }; }, componentWillMount: function() { // when React renders me, I subscribe to the topic 'PRODUCT_CLICKED' // and .subscribe returns a unique token necessary to unsubscribe this.pubsub_token = PubSub.subscribe('PRODUCT_CLICKED', function(topic, product) { // update my selection when there is a message this.setState({ selection: product }); }.bind(this)); }, componentWillUnmount: function() { // React removed me from the DOM, I have to unsubscribe from the PubSub using my token PubSub.unsubscribe(this.pubsub_token); }, render: function() { return ( <div>You have selected the product: {this.state.selection}</div> ); } })
var subscriber_token = PubSub.subscribe('MJPEG', function(msg, data) {
}); this.token_GATHERING_SELECT = PubSub.subscribe('GATHERING_SELECT', this.gatheringSelect); }, componentWillUnmount: function() {
}); this.token_SESSION_CARE = PubSub.subscribe('SESSION_CARE', this.sessionCare); this.token_GATHERING_SELECT = PubSub.subscribe('GATHERING_SELECT', this.gatheringSelect); this.token_BACKBUTTON_CLICK = PubSub.subscribe('BACKBUTTON_CLICK', this.backButtonClick); this.token_POPUP_OPEN = PubSub.subscribe('POPUP_OPEN', this.popupOpen); this.token_POPUP_CLOSE = PubSub.subscribe('POPUP_CLOSE', this.popupClose); }, componentWillUnmount: function() {
this.token_POPUP_CLOSE = PubSub.subscribe('POPUP_CLOSE', this.popupClose); }, componentWillUnmount: function() {
this.token_GATHERINGS_REFRESH = PubSub.subscribe('GATHERINGS_REFRESH', function(topic) { this.refreshGatherings(); }.bind(this));