Search code examples
reactjsrefluxjs

Disconnect Reflux listenTo method


So, I have two stores. First pageStore serves business logic of specific page, and second globalStore logic of Android/iOS global events. When user enters specific page React.componentDidMount calls

pageEntered: function () {
    this.listenTo(globalStore, this.locationUpdated);
},

so from this my pageStore started to listen global storage for GPS updates. But is there any way to disconnect listenTo on React.componentWillUnmount ?


Solution

  • There's an example how to unsubscribe from a store listening (taken from the official examples):

    var Status = React.createClass({
        getInitialState: function() { },
        onStatusChange: function(status) {
            this.setState({
                currentStatus: status
            });
        },
        componentDidMount: function() {
            this.unsubscribe = statusStore.listen(this.onStatusChange);
        },
        componentWillUnmount: function() {
            this.unsubscribe();
        },
        render: function() {
            // render specifics
        }
    });