reflux / refluxjs

A simple library for uni-directional dataflow application architecture with React extensions inspired by Flux
BSD 3-Clause "New" or "Revised" License
5.36k stars 330 forks source link

How to stop listening? #508

Closed DrikoArgon closed 7 years ago

DrikoArgon commented 7 years ago

This should be a really newbie question, but how can I stop listening to an action?

I've been following a video in youtube to learn how to use react with firebase, and the teacher decided to use reflux to manage data flow. When it comes to the part where my component needs to know when the action of loading my user ends, so I can go to the main screen, the guy in the video binded a listener to the action, using something like this: Actions.loadUser.completed.listen(this.MyMethod.bind(this)). Everything worked perfectly, but I don't know how to stop listening to this, and now everytime the load user Action is completed my app goes to the main screen... Can someone help me please?

BryanGrezeszak commented 7 years ago

Listeners return an unsubscribe. So it should work something like this:

var unsub = Actions.loadUser.completed.listen(this.MyMethod.bind(this));

// later
unsub(); // unsubscribes

I think this got left out of the new docs...so totally not your fault. I'll get it added into the docs in the next update.

DrikoArgon commented 7 years ago

Thank you very much! :D