Search code examples
fluxrefluxjs

Calling UI action from store


Short version of the question:

Can I fire UI actions from the store?

Long version of the question:

I'm writing food delivery app with reflux. It's seems like I'm not quite understand how actions should go in my applications.

I have BasketStore, StatusOverlay (component) and actions:

// BasketStore actions
basketSync
basketSync.Completed
basketSync.Invalid
basketSync.Failed

// StatusOverlay actions
statusOverlayOpen
statusOverlayClose

The application works the following way:

I press button and send basketSync action. Once it happened the overlay is starting to be shown and BasketStore sends request for the data to the server.

Then accordingly to server response I fire basketSync.completed, basketSync.failed, basketSync.invalid. When it invalid or completed I close overlay, otherwise I show another overlay.

The question is how should I manage actions? Should I listen to basketSync inside of StatusOverlay to open it and close it on basketSync.completed, basketSync.invalid or it will be better to listen to just statusOverlayOpen, statusOverlayClose and fire these actions somewhere inside of BasketStore.


Solution

  • Short answer: In the standard Flux architecture, Flux stores should only emit a simple CHANGE event, so, no, you can't fire UI actions from the store.