0

I am working on a JS application using the Flux architecture. Among other things, the application displays a list of contacts and on each of them you can add or remove them from your contact book.

The application is doing optimistic UI updates, so in this case you can click on 'add' and see 'remove' right away while in the background we are doing the ajax request to add the contact.

However I do not know how to handle the case when someone clicks on 'remove' while we are still adding the contact. The 'remove' ajax request expects an ID that we do not have yet. It is also a requirement that I cannot grey out the 'remove' button while the request is running.

My ideal way I think would be to be able to dispatch actions that are dependent on other action. Is that a good idea, how can I implement that?... :/

Do you guys know how I should handle this case in a flux application architecture?

Gregory
  • 557
  • 6
  • 17
  • Another example would be the Like button on Facebook, you can click forever on Like & Unlike. I wonder how they handle the network calls... – Gregory Jun 05 '15 at 00:57

1 Answers1

0

Optimistic updates are great -- but putting a "Remove" link that is incoherent makes no sense. Why not add the contact on the page but wait to add the "Remove" until you're notified by the store that the addition was successful?

Hal Helms
  • 684
  • 3
  • 8