0

When using React with Reflux, stores have only one event for components to listen to. Assuming that:

  • I have a ProductStore that contains a list of products
  • I have two components that listen to changes in this store: a product list that is interested in all changes and a detail page that only cares about updates on a specific product

How can I distinguish between a 'list_refreshed' or 'item_updated' event, where the first would signal a complete refresh of the list of products and the latter merely an update of a single item?

efdee
  • 2,255
  • 3
  • 20
  • 26

1 Answers1

0

Not sure on your exact scenario, but what i did for something similar, was update a boolean or property on a store. Then emit the event to the top level component. The top level component would then pass the appropriate change depending on the return value of a boolean from the store, down the chain.

Can see here i get a boolean value from the ItemStore: https://github.com/agmcleod/desert/blob/master/js/components/ProjectShow.react.js#L22

https://github.com/agmcleod/desert/blob/master/js/components/ProjectShow.react.js#L165

Then i pass it down to an ItemList component, which will render an empty item with a text box if it's true. I have an action that triggers the store to set that boolean to true.

agmcleod
  • 13,321
  • 13
  • 57
  • 96