Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Are stores allowed to send actions to other stores? #196

Closed
moreofmorris opened this issue Jan 20, 2015 · 5 comments
Closed

Are stores allowed to send actions to other stores? #196

moreofmorris opened this issue Jan 20, 2015 · 5 comments
Labels

Comments

@moreofmorris
Copy link

Hello.

I'm using Reflux and React for a prototype at work and I'm wondering, is it convention with Reflux for stores to send actions, like I send actions from components, for other stores to listen and respond to? I only ask, as I have a couple of stores that rely on other data from other stores. When I use the listenTo method on a store that listens to another store, everything gets quite complex and I've also run into what seems to be circular errors, it just won't run.

I'm very used to Backbone and how it handles data. I'm just having a hard time wrapping my head around how Reflux is meant to do things. I've read that I can't have stores calling actions, that should only be in the components, but then I don't really know how to get data from other stores and make sure everything is synced.

@spoike
Copy link
Member

spoike commented Jan 21, 2015

Where did you read that you can't have stores calling other actions? If it is in our documentation then that needs to be changed. Here is a discussion about the contrary

tl;dr:

  • YES, you may send actions from a store.
  • Stores are meant to emit events when its data changes, other "kinds" of events from the store should be implemented as actions that triggers new data flows.

@moreofmorris
Copy link
Author

I was basing this on the documentation, or at least my understanding of it. That if a store data depends on another store data it should simply listen to it's trigger with this.listenTo... and do what it needs there. But this was causing so many issues for me, but as soon as I just let my store do actions.updateNowPlaying() for example, any store could simply respond to that particular action... My code suddenly was then much easier to deal with.

I worry though that this isn't really how the data should be flowing, or it's not really the "right way" somehow as in my mind it was creating lots of crazy data flows in my app that would be hard to pin down. But maybe it's just my understanding of it all is a little confused.

So in essence, when a store called this.trigger(...) it's really just the components that will respond to this, and maybe another store with this.listenTo(...) if the data flow requires it (that store absolutely requires the updated data from the previous store). But on the whole, having stores triggering actions where other stores listen to it, really is ok... ?

@spoike
Copy link
Member

spoike commented Jan 21, 2015

I was basing this on the documentation, or at least my understanding of it. ... (snip snip)

Yeah, I should probably make it a bit more explicit. The reason you can chain data stores is if you want to do some transformation of the same data. I guess I need to make this more explicit in the documentation.

But on the whole, having stores triggering actions where other stores listen to it, really is ok... ?

Again: YES, it's OK. (Don't you worry 'bout a thing 🎶)

@moreofmorris
Copy link
Author

Thank you dude.

I suppose I was confused over the documentation, I've been banging my head against a brick wall because of it. An appropriate update might help others out too (unless it's just me being dumb all on my own). Great work on this project!

@DeepAnchor
Copy link

I was a bit confused about this also (invoking actions from stores). Not sure if it's just me, but the diagram in the wiki here seems to be suggesting that only components should invoke actions. Anyways, this project has been very useful, thanks for all the work that you've put into it @spoike !

@spoike spoike closed this as completed Jul 11, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants